ezcrypto – ruby gem for encrypting and decrypting
ezcrypto is a Ruby wrapper around the openssl library which allows you to encrypt and decipher text.
You can install ezcrypto as a gem.
Installing ezcrypto as a gem
sudo gem install ezcrypto
ezcrypto sample code
Contents of file encrypt.rb:
require 'rubygems'
require 'ezcrypto'
key = EzCrypto::Key.with_password('some password', 'some system salt', :algorithm => 'des')
encrypted_text = key.encrypt('This is the text you want to encrypt')
decrypted_text = key.decrypt(encrypted_text)
puts "Here is deciphered text, which was first encrypted and now deciphered: " + decrypted_text
Output:
Here is deciphered text, which was first encrypted and now deciphered: This is the text you want to encrypt
ezcrypto documentation
One Comment to “ezcrypto – ruby gem for encrypting and decrypting”
Leave a Reply


Also check out the shuber-attr_encrypted gem. That’s what I’ve been using. Instead of encrypting specific text, it converts selected model attributes to be encrypted before they’re saved to the database, and decrypted after being read back in.