Created
April 7, 2016 04:51
-
-
Save shikendon/0a3e8030ce2c0336fd8e509c1ad0ae52 to your computer and use it in GitHub Desktop.
RIJNDAEL 128 CBC (AES-256-CBC) encryption Ruby snippet
This file contains 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' | |
key = '12345678901234567890123456789012' | |
iv = '1234567890123456' | |
data = 'abcdefghijklmnop' | |
cipher = OpenSSL::Cipher::AES.new(256, :CBC) | |
cipher.encrypt | |
cipher.padding = 32 | |
cipher.key = key | |
cipher.iv = iv | |
encrypted = cipher.update(data) + cipher.final | |
encrypted = encrypted.unpack('H*') | |
puts encrypted # b91d3ece42c203729b38ae004e96efb9b64c41eeb074cad7ebafa3973181d233 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment