Created: 2008-08-28 03:16
Updated: 2018-01-07 03:21
License: mit



Written by Alex Boussinet
Modified by Mark Percival

This ruby gem is simply a modification of Alex Boussinet's Ruby-AES(normal implemenation) which can be found at

I've fixed 2 issues to make it compatible with OpenSSL:

  • Correctly padding the blocks
  • Generating a key and IV from a password and random salt

require 'rubygems'
require 'ruby-aes'
require 'base64'

enc = Aes.openssl_encrypt("pass", "test", :salt => "1831BD4EC8E35CC8", :size => 256, :mode => 'CBC')
p Base64.b64encode(enc[:salted])
dec = Aes.openssl_decrypt("pass", enc[:salted])
p dec

Valid modes are:

  • ECB (Electronic Code Book)
  • CBC (Cipher Block Chaining)
  • OFB (Output Feedback)
  • CFB (Cipher Feedback)

Valid key length:

  • 128 bits
  • 192 bits
  • 256 bits

For a really good encryption, 256 bits CBC is recommanded.

For more information on AES-Rijndael, see:

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more