https://github.com/emartech/ruby-easy-crypto
Provides simple wrappers around the openssl crypto implementation.
https://github.com/emartech/ruby-easy-crypto
Last synced: about 1 year ago
JSON representation
Provides simple wrappers around the openssl crypto implementation.
- Host: GitHub
- URL: https://github.com/emartech/ruby-easy-crypto
- Owner: emartech
- License: mit
- Created: 2018-06-21T11:40:33.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-06-08T12:01:39.000Z (about 4 years ago)
- Last Synced: 2025-07-01T08:42:43.441Z (about 1 year ago)
- Language: Ruby
- Size: 43.9 KB
- Stars: 2
- Watchers: 13
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# EasyCrypto [](https://travis-ci.org/emartech/ruby-easy-crypto) [](https://badge.fury.io/rb/easy-crypto)
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:
```ruby
gem 'easy-crypto'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install easy-crypto
## Simple usage (Recommended)
```ruby
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](https://en.wikipedia.org/wiki/Key_derivation_function) 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.
```ruby
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](https://opensource.org/licenses/MIT).