app.rb
# encrypt a string using a pre-defined encryption key
encrypt a string using a pre-defined encryption key
encrypt a string using a pre - defined encryption key
def encrypt(unencrypted_text,encryption_key)
    cipher = OpenSSL::Cipher::AES256.new :CFB
    cipher.encrypt
    iv = cipher.random_iv
    encrypted_iv = Base64.encode64(iv)
    cipher.key = encryption_key
    encrypted_text = Base64.encode64(cipher.update(unencrypted_text) + cipher.final)
    encrypted_result           = Hash.new
    encrypted_result['params'] = encrypted_text
    encrypted_result['iv']     = encrypted_iv
    return encrypted_result
  end
def encrypt ( unencrypted_text , encryption_key ) cipher = OpenSSL :: Cipher :: AES256 . new :CFB cipher . encrypt iv = cipher . random_iv encrypted_iv = Base64 . encode64 ( iv ) cipher . key = encryption_key encrypted_text = Base64 . encode64 ( cipher . update ( unencrypted_text ) + cipher . final ) encrypted_result = Hash . new encrypted_result [ 'params' ] = encrypted_text encrypted_result [ 'iv' ] = encrypted_iv return encrypted_result end
encrypt a string using a pre-defined encryption key
encrypt a string using a pre - defined encryption key
# initialize new cipher object # generate random Initialization Vector (iv) aka Salt # the iv will be returned together with the encrypted string because it is required when decrypting # set the predefined encryption_key as the cipher.key # encrypt the string and Base64 encode it # create new hash to store the IV and encrypted string
unencrypted_text
<not_specific>
encryption_key
<not_specific>