Skip to content
Encrypt attributes on an ActiveRecord model.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
tasks
test
.gitignore
MIT-LICENSE
README
Rakefile
TODO
init.rb

README

Has Encrypted Attributes
=====================================

Allows a model to store attributes encrypted in the database. It seamlessly 
encrypts/decrypts the data for use within the application.

Set the key in the definition using :key => <key string> or by providing an 
association that contains the key.

Using :except in the definition allows for unencrypted attributes in the mix.
By default the _id of the association is excluded (ie: user_id), if needed 
and the usual created_at, updated_at, created_on, updated_on columns.

Requires:
  Ruby compiled with OpenSSL turned on (and in turn with Blowfish turned on)

Example
=====================================

Inline key:

class Secrets
  has_encrypted_attributes :key => 'THIS IS MY KEY TEXT'
end

Key residing on an association:

class MoreSecrets
  has_encrypted_attributes :association => :user
  # looks for key in self.user.key
end

Key residing on an association (with a custom name for the key):

class StillMoreSecrets
  has_encrypted_attributes :association => :user, :key_method => :salt
  # looks for key in self.user.salt
end

You can also encrypt only some of the model attributes:

class MostSecrets
  has_encrypted_attributes :except => [:year, :count]
  # will not try to encrypt year and count attributes
end

Copyright (c) 2008, 2009 Shawn Veader & Jordi Bunster. Licensed under MIT's.
Something went wrong with that request. Please try again.