Skip to content

getaasciesh/encrypted

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Encrypted

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.

Installation

Add this line to your application's Gemfile:

gem 'encrypted'

And then execute:

$ bundle

Or install it yourself as:

$ gem install encrypted

Usage

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.

Encryption

    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)

Decryption

    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.'"

Key and IV generation helper

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)
    

Contributing

  1. Fork it ( https://github.com/getaasciesh/encrypted/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

Rijndael CBC encryption decryption.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages