Crypto in ruby

Published June 16th, 2005 edit replace rm!

Nick asked on ruby-talk how to do simple encryption using ruby and it’s built in OpenSSL module.

I’ve just registred an ezcrypto module at rubyforge, which should make it a lot easier to use. There currently is no code there, but I will be uploading something shortly.

However to get started here is a little starter:

require 'openssl'
require 'digest/sha2'
cipher = OpenSSL::Cipher::Cipher.new('aes-192-cbc')  
cipher.encrypt
cipher.key=Digest::SHA256.digest("super secret password")
encrypted= cipher<<"data to be encrypted..." # Note this needs to be padded to be the block size of the cipher.

To do decrypt just use cipher.decrypt instead.

Comments
rubyonrails@datanomisch.de

Timo Mika Gläßer November 3rd, 2007

Hey,

do you actually know if it is possible to have multiple signing keys thus allowing multiple users toi decrypt a model in ezcrypto?

Regards

Timo&*

About me

Pelle gravatar 160

My name is Pelle Braendgaard. Pronounce it like Pelé the footballer (no relation). CEO of Notabene where we are building FATF Crypto Travel Rule compliance software.

Most new articles by me are posted on our blog about Crypto markets, regulation and compliance

More about me:

Current projects and startups:

Other under Programming

Popular articles

Topics: