Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A Rails Engine for Storing Encrypted Data with Strongbox (no longer maintained)
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app flash[:error] with message if wrong password
config initial commit
lib typo
rails initial commit
tasks initial commit
test initial commit
.gitignore gitignore
LICENSE Version bump to 0.1.0
README.markdown
Rakefile
VERSION Version bump to 0.1.7
init.rb initial commit
install.rb initial commit
safe.gemspec
uninstall.rb initial commit

README.markdown

Safe

A wrapper around strongbox to store and encrypt data.

Setup

Install strongbox and safe

config.gem "spikex-strongbox", :lib => "strongbox", :source => "http://gems.github.com"
config.gem "bitzesty-safe", :lib => "safe", :source => "http://gems.github.com"

rake gems:install
rake gems:unpack

Generate a migration with script/generate migration CreateSafeCabinet and add the following

class CreateSafeCabinet < ActiveRecord::Migration
  def self.up
    create_table :safe_cabinets, :force => true do |t|
      t.binary :data
      t.binary :data_key
      t.binary :data_iv
      t.integer :encryptable_id
      t.string :encryptable_type
      t.timestamps
    end
    add_index :safe_cabinets, [:encryptable_id, :encryptable_type]
  end

  def self.down
    drop_table :safe_cabinet
  end
end

In your model that you want to store the encrypted data add:

class MyModel
  include Safe::Keys
  attr_accessor :password #length must be > 3  
  has_many :safe_cabinets, :as => :encryptable #or has_one
  after_create :make_keys!
end

Make sure you are not logging the data/password by adding the following in your ApplicationController

filter_parameter_logging :data
filter_parameter_logging :password

N.B. A password must be used when creating an instance of MyModel.

To create and use safe_cabinets:

m = MyModel.create(:password => "1234")
c = m.safe_cabinets.new
c.data = "super secret data"
c.save

c.data
=> #<Strongbox::Lock:0x1f372d...

c.data.read_data("1234")
=> "super secret data"

Copyright (c) 2009 Matthew Ford and Bit Zesty Ltd, See LICENSE for details.

Something went wrong with that request. Please try again.