DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Encrypting Data With Ruby And OpenSSL
require 'openssl'
require 'digest/sha1'
c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
c.encrypt
# your pass is what is used to encrypt/decrypt
c.key = key = Digest::SHA1.hexdigest("yourpass")
c.iv = iv = c.random_iv
e = c.update("crypt this")
e << c.final
puts "encrypted: #{e}\n"
c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
c.decrypt
c.key = key
c.iv = iv
d = c.update(e)
d << c.final
puts "decrypted: #{d}\n"provided by menik from #rubyonrails






Comments
Snippets Manager replied on Fri, 2010/06/11 - 4:39pm
Snippets Manager replied on Tue, 2011/04/05 - 10:44am
Snippets Manager replied on Mon, 2007/12/10 - 2:14pm
Snippets Manager replied on Sat, 2006/08/26 - 8:33pm
Snippets Manager replied on Mon, 2006/09/11 - 12:26pm
Snippets Manager replied on Sat, 2006/08/26 - 8:33pm
Snippets Manager replied on Sat, 2006/08/26 - 8:33pm
Snippets Manager replied on Thu, 2006/04/27 - 3:10pm