veader / has_encrypted_attributes

Encrypt attributes on an ActiveRecord model.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Encrypt attributes on an ActiveRecord model.

License:MIT License


Languages

Language:Ruby 100.0%