Ruby on Rails gem for encryption and decryption with Rijndael algorithm and CBC.
Key size options: 128, 192 and 256 bits Block size options: 128, 192 and 256 bits
AES is version of Rijndael with 128 bits block size. Hence, to encrypt/decrypt with AES standard choose any key size but 128 bits block size.
Add this line to your application's Gemfile:
gem 'encrypted'And then execute:
$ bundle
Or install it yourself as:
$ gem install encrypted
Mode needs to be supplied when instantiating Encrypted::Ciph. Mode consists of desirable key length and block length in "keysize-blocksize" format. "256-128" implies key size of 256 bits and block size of 128 bits.
encrypt_this = "This is seriously confidential message."
cipher = Encrypted::Ciph.new("256-256")
key = "xvxvxvxxvxvxvxvxvxvxvxvxvxvxvxvx" # 256 bits / 8 = 32 bytes
iv = "nmnmnmnmnmnmnmnmnmnmjkjkhjhjhjgh" # 256 bits / 8 = 32 bytes
cipher.key = key
cipher.iv = iv
encrypted_text = cipher.encrypt(encrypt_this) decrypt_this = encrypted_text #from above
decipher = Encrypted::Ciph.new("256-256")
cipher.key = "xvxvxvxxvxvxvxvxvxvxvxvxvxvxvxvx" #key used above to encrypt
cipher.iv = "nmnmnmnmnmnmnmnmnmnmjkjkhjhjhjgh" #initialization vector used above
decrypted_text = cipher.decrypt(decrypt_this)"decrypted_text => 'This is some seriously confidential message.'"
To automatically generate and assign right size of random key and iv bytes while encrypting.
encrypt_this = "This is seriously confidential message. Let me generate stuff for ya."
cipher = Encrypted::Ciph.new("256-128")
key = cipher.generate_key # Sets and returns 32 bytes long string
iv = cipher.generate_iv # Sets and returns 16 bytes long string
encrypted_text = cipher.encrypt(encrypt_this)
- Fork it ( https://github.com/getaasciesh/encrypted/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request