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.

sudo gem install ezcrypto

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
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Facebook Twitter Email

One Comment to “ezcrypto – ruby gem for encrypting and decrypting”

  1. Mike Fischer 9 January 2010 at 7:44 pm #

    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.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

Leave a Reply