Musings about Coding, Business and other Geek Stuff Live and Direct from somewhere on the planet
October 19, 2005
ActiveCrypto for Ruby on Rails

The past week I’ve been working on creating a layer on top of my EzCrypto library for ruby to make it a bit easier for use in Ruby on Rails.

Basically I have a bunch of projects that all need to use Crypto. The way I’ve done it in StakeItOut was fine, but hand coded and a bit of a pain to implement in a bunch of different products.

I talked to David about this a while ago, but haven’t had the time to do it until now. Now I need it myself so I’m writing it.

This is just a sneak peak of what the mode might look like right now:

class User < ActiveRecord::Base
	has_many :documents
	keyholder
end

class Document < ActiveRecord::Base
	encrypt :title,:body, :key=>:user
	belongs_to :user
end

This defines the User as the keyholder, which means that the user contains a key for encryption and decryption. Document is the actual encrypted class. You basically specify the attributes that you want to keep encrypted and tell it from where you want to get the key. In this case we get the key from the User.

The following code gives you example code that shows how you would use it in practice.

@user=User.new
@user.name="bob"
@user.save
@user.enter_password "shh" # Creates a key based on password

@doc=Document.new
@doc.user=user
@doc.title="Secret article"
@doc.body="h1. shh!"
@doc.save

I will explain more later once I’ve worked out all the kinks of it. I’ve been getting into some really hairy hard core ruby stuff.

Posted by pelleb at October 19, 2005 05:14 PM
This entry was posted in the following Categories: Crypto & Security , Ruby
Comments
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?