I have just released the latest version of EzCrypto which has the new Rails support I mentioned in my last post.
Everything is as transparent as possible. See the EzCrypto docs for more info.
I will try to write a bit more about it later.
The only thing I just want to write about is that it currently supports the following two usage patterns:
@doc=Document.new
@doc.enter_password "my very own secret"
@doc.title="Plan to take over the world"
@doc.save
This is probably not very useful, but it is the simplest of all patterns.
This is mirrors a database one to many pattern where the parent has the key and is known in ActiveCrypto as the KeyHolder.
@user=User.new
@user.enter_password
@user.save
@doc=Document.new
@doc.user=@user
@doc.title="Plan to take over the world"
@doc.save
This will probably be the most useful of the two patterns.
This pattern is not implemented yet in ActiveCrypto, although I do use it in StakeItOut. I am working on a way to simplify the usage of it to make it as easy and straightforward to use as the One key many records pattern. I am guessing version 0.3 will have this.
I welcome feedback. As mentioned I am doing for me some pretty hairy ruby programming linking it into Rails. I would like to hear suggestions from some of the actual Rails frameworks maintainers and others about what could be done to improve it and integrate it even better into 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.