Add encrypted fields to ActiveRecord models easily
Add this line to your application's Gemfile:
And then execute:
$ rails action_encrypt:install:migrations
action_encrypt.rb in your initializers folder and set encryption keys. Generate them
SecureRandom.hex(32). You can decide between storing the values in ENV or using rails encrypted credentials system.
ActionEncrypt.configure do |config| config.key_encryption_key = ENV.fetch('KEY_ENCRYPTION_KEY') config.blind_index_key = ENV.fetch('BLIND_INDEX_KEY') end
Create a Data Encryption Key
$ ActionEncrypt::DataEncryptionKey.generate!(primary: true)
Add an encrypted field to your models
class User < ApplicationRecord has_encrypted :ssn end
Now you can use user.ssn as you would any other attribute, but it will be stored securely in the action_encrypt_encrypted_fields table.
Contribution directions go here.
The gem is available as open source under the terms of the MIT License.