Skip to content

Instantly share code, notes, and snippets.

@misha-krainik
Created September 14, 2016 09:34
Show Gist options
  • Save misha-krainik/a2a1cee016f96750908cbdc8b116e411 to your computer and use it in GitHub Desktop.
Save misha-krainik/a2a1cee016f96750908cbdc8b116e411 to your computer and use it in GitHub Desktop.
require 'openssl/cipher'
module Cipher
Algorithm = 'aes-256-cbc'
def encrypt(text, key)
cipher = OpenSSL::Cipher::Cipher.new(Cipher::Algorithm)
cipher.encrypt
cipher.pkcs5_keyivgen(key)
secret = cipher.update(text)
secret << cipher.final
secret
end
def decrypt(text, key)
cipher = OpenSSL::Cipher::Cipher.new(Cipher::Algorithm)
cipher.decrypt
cipher.pkcs5_keyivgen(key)
nosecret = cipher.update(text)
nosecret << cipher.final
nosecret
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment