Created
September 14, 2016 09:34
-
-
Save mykhailokrainik/a2a1cee016f96750908cbdc8b116e411 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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