AFAIK, aes stone wraps the Ruby openssl standard library to provide a much more simplified interface. It only supports aes-256-cbc , which is a 256-bit AES with an encryption chain. You would probably add encryption / decryption methods to your models in Rails.
The basic procedure for encryption:
- compute AES symmetric encryption key, 256 bits
- it is not necessary to compute the initialization vector for use with
aes-256-cbc (the aes stone can actually do this for you, so you can skip this step) - encrypt your message, optionally indicating the output
:format (Base64 by default, otherwise simple Ruby string strings) and / or initialization vector :iv
This will:
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 $
Then you decrypted enc64 , passing in the whole :iv + $ + encrypted message line, as well as the 256-bit AES key .
AES.decrypt(enc64, key) => "hello, secret world"
Having some experience using the standard openssl library in Ruby, I can tell you that the English documentation is sparse, while the Japanese documentation is very good. Anyway, using the openssl API is confusing at best, so if you don't mind restricting yourself to aes-256-cbc , then this aes stone looks very useful.
Remember, the author has a caution regarding speed. If you find that you need a faster solution, you should take a look at FastAES . FastAES is a C extension and will require a compiler for your target platform.
buruzaemon
source share