Skip to content

Instantly share code, notes, and snippets.

@shikendon
Created April 7, 2016 04:51
Show Gist options
  • Save shikendon/0a3e8030ce2c0336fd8e509c1ad0ae52 to your computer and use it in GitHub Desktop.
Save shikendon/0a3e8030ce2c0336fd8e509c1ad0ae52 to your computer and use it in GitHub Desktop.
RIJNDAEL 128 CBC (AES-256-CBC) encryption Ruby snippet
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