CipherStash
CipherStash Documentation

Getting started

This tutorial will run you through installing ActiveStash in your existing Rails app that is using an application level encryption library such as Lockbox or ActiveRecord Encryption.

To learn how to setup application level encryption visit the below links.

You’re now ready to install ActiveStash.

  1. Add ActiveStash to your Gemfile:
gem "active_stash"
  1. Install the new dependencies:
$ bundle install
  1. Create a CipherStash account (which will provision you a workspace) and then login:
$ rake active_stash:login[YOURWORKSPACEID]

Note: If you are using zsh you may need to escape the brackets:

$ rake active_stash:login\['WorkspaceId'\]
  1. Any model you use with ActiveStash::Search needs to have a stash_id column.

    The stash_id column is used to link search results back to encrypted database records.

    For example, to add a stash_id column to the database table for the User model, add the below migration:

$ rails g migration AddStashIdToUser stash_id:string:index
$ rails db:migrate
  1. Add the ActiveStash::Search mixin to your user model, and declare what fields are searchable:
# app/models/user.rb
class User < ApplicationRecord
  include ActiveStash::Search

  # Previously added application-level encryption, by either ActiveRecord Encryption or Lockbox
  encrypts :name, :email
  encrypts :dob, type: :date

  # Fields that will be indexed into CipherStash
  stash_index :name, :email, :dob

end
  1. Reindex your existing encrypted database records into CipherStash:
$ rails active_stash:reindexall

If you want to just reindex one model, for example User, run:

$ rails active_stash:reindex[User]

You can also reindex in code:

User.reindex

Depending on how much data you have, reindexing may take a while but you only need to do it once.

ActiveStash will automatically index (and delete) data as it records are created, updated and deleted.

For more information visit the ActiveStash Ruby docs.