I am brand new to Ruby, so I apologize if this question is simple. I have to update a rails app so that it encrypts a string using a key. This is passed to an api written in django, where the encrypted string will be decrypted using the same key. I have the following code in Python, but I'm not sure how to encrypt the associated message in Ruby. Any help would be appreciated.
import base64
from Crypto.Cipher import AES
from Crypto import Random
class AESCipher:
def __init__( self, key ):
self.key = key
def encrypt( self, raw ):
raw = pad(raw)
iv = Random.new().read( AES.block_size )
cipher = AES.new( self.key, AES.MODE_CBC, iv )
return base64.b64encode( iv + cipher.encrypt( raw ) )
def decrypt( self, enc ):
enc = base64.b64decode(enc)
iv = enc[:16]
cipher = AES.new(self.key, AES.MODE_CBC, iv )
return unpad(cipher.decrypt( enc[16:] ))