EasyCrypto Build Status Gem Version

Provides simple wrappers around the openssl crypto implementation. The library provides two interfaces: simple and advanced. Simple mode is designed for ease-of-use and advanced mode provides some performance benefits in certain use-cases. See below for more details.

All the underlying crypto operations are the same.

Installation

Add this line to your application's Gemfile:

gem 'easy-crypto'

And then execute:

$ bundle

Or install it yourself as:

$ gem install easy-crypto
require 'easycrypto'

password = 'secret password'
plaintext = 'some data'

ecrypto = EasyCrypto::Crypto.new

encrypted = ecrypto.encrypt(password, plaintext)
decrypted = ecrypto.decrypt(password, encrypted)

decrypted == plaintext

Advanced usage (Use for performance)

Key derivation is a resource heavy process. The simple interface abstracts this away and forces you to recompute the key before each encryption/decryption process.

This interface allows you to cache the result of the key derivation. This is required if you need to encrypt/decrypt multiple times with the same derived key. Caching the key saves you the time to have to recompute it before every encryption/decryption.

require 'easycrypto'

password = 'secret password'
plaintext = 'data to encrypt ...'

ecrypto = EasyCrypto::Crypto.new

key = EasyCrypto::Key.generate(key_password)

encrypted = ecrypto.encrypt_with_key(key, plaintext)
decrypted = ecrypto.decrypt_with_key(key, encrypted)

decrypted == plaintext

License

The gem is available as open source under the terms of the MIT License.