ActiveCrypto for RoR

EzCrypto 0.2 with ActiveCrypto support for Rails - the idea
is to add cryptography via a single line or two of code in your
activerecord model and another line or two in a controller somewhere.
Examples:

# app/model/user.rb
#  A KeyHolder is an object that holds keys for use by other objects
class User < ActiveRecord::Base
   has_many :documents
   keyholder
end

# app/model/document.rb
class Document < ActiveRecord::Base
   belongs_to :user
   encrypt :title,:body,:key=>:user
end

# in controllers
@user=User.new
@user.enter_password "This stuff is secret man!!!"
@user.save

@doc=Document.new
@doc.user=@user
@doc.title="Plan to take over the world"
@doc.body="Write apps in Rails"
@doc.save

Decryption is done transparently.

When doing this within a rails application, active_crypto automatically maintains a list of keys for each user session. Besides the 2 steps below you don't need to do anything special within your controller.

  • When a user logs on with a password enter his password like this:
@user.enter_password @params['password']
  • When a user logs off call the following
clear_session_keys