AFAIK, the aes gem wraps the openssl Ruby standard library to provide a much more simplified interface. It supports only aes-256-cbc, which is 256-bit AES with cipher-block chaining. You would probably add encryption/decryption methods to your models in Rails.
The basic order of operation for encryption would be:
- compute an AES symmetric encryption key, 256 bits
- optionally compute an initialization vector for use with
aes-256-cbc (the aes gem can actually do this for you, so you could skip this step)
- encrypt your message, optionally indicating output
:format (Base64 by default, otherwise plain Ruby byte-strings) and/or initialization vector :iv
That would be:
key = AES.key
=> "6476b3f5ec6dcaddb637e9c9654aa687" # key ends up as a 32-char long hex string
iv = AES.iv(:base_64)
=> "PPDRCMsZhumCdEO1Zm05uw=="
enc64 = AES.encrypt("hello, secret world", key, {:iv => iv})
=> "PPDRCMsZhumCdEO1Zm05uw==$b3CCy/1dAMJ2JG5T50igEMGtvo9Ppkla1c9vrKbo+zQ="
# note that the encrypted result is the :iv
# and Base64-transformed encrypted message
# concatenated with $
You would then decrypt enc64 by passing in the entire :iv + $ + encrypted message string, as well as the AES 256-bit key.
AES.decrypt(enc64, key)
=> "hello, secret world"
Having had some experience using the openssl standard library in Ruby, I can tell you that the documentation in English is sparse, while the Japanese documentation is very good. At any rate, using the openssl API is confusing at best, so if you do not mind limiting yourself to aes-256-cbc, then this aes gem looks to be very helpful.
Mind you, the author does have a caveat with regards to speed. If you find that you require a faster solution, you should have a look at FastAES. FastAES is a C-extension, however, and will require a compiler for your target platform.