ActiveCrypto::ClassMethods

Usage is very simple. You will generally only need the two class methods listed here in your ActiveRecord class model.

License

ActiveCrypto and EzCrypto are released under the MIT license.

Support

To contact the author, send mail to pelleb@gmail.com

Also see my blogs at: stakeventures.com and neubia.com

This project was based on code used in my project StakeItOut, where you can securely share web services with your partners. stakeitout.com

(C) 2005 Pelle Braendgaard

Public Instance Methods

encrypt(*attributes) click to toggle source

Turn encryption on for this record. List all encrypted attributes

class Document < ActiveRecord::Base
              encrypt :title,:body
      end

Options are:

<tt>key</tt> - to specify an external KeyHolder, which holds the key used for encrypting and decrypting
<tt>base64</tt> - set to true in order to base64 encode the encrypted attributes.  defaults to false

class Document < ActiveRecord::Base
      belongs_to :user
      encrypt :title,:body,:key=>:user, :base64 => true
end
# File lib/active_crypto.rb, line 52
def encrypt(*attributes)        
  include ActiveCrypto::Encrypted
  before_save :encrypt_attributes
  after_save :decrypt_attributes
  options=attributes.last.is_a?(Hash) ? attributes.pop : {}
  keyholder
  if options and options[:key]
                          module_eval                                         def session_key                                                (send :#{options[:key]} ).send :session_key                                        end                                               @@external_key=true                              
  end

  base64_encode = (options and options[:base64])
  module_eval           def self.ezcrypto_base64?            #{base64_encode.to_s}          end
  
  self.encrypted_attributes=attributes
end
keyholder() click to toggle source

Creates support in this class for holding a key. Adds the following methods:

  • enter_password(password,salt="onetwothree")

  • set_session_key(key)

  • session_key

Use it as follows:

class User < ActiveRecord::Base
      has_many :documents
      keyholder
end
# File lib/active_crypto.rb, line 92
def keyholder()
  include ActiveCrypto::AssociationKeyHolder   
  after_create :save_session_key       
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.