README.md in lockbox-0.2.4 vs README.md in lockbox-0.2.5

- old
+ new

@@ -42,18 +42,36 @@ Lockbox.master_key = Rails.application.credentials.lockbox_master_key ``` Alternatively, you can use a [key management service](#key-management) to manage your keys. +## Instructions + +Database fields + +- [Active Record](#active-record) +- [Mongoid](#mongoid) + +Files + +- [Active Storage](#active-storage) +- [CarrierWave](#carrierwave) +- [Shrine](#shrine) +- [Local Files](#local-files) + +Other + +- [Strings](#strings) + ## Database Fields ### Active Record Create a migration with: ```ruby -class AddEmailCiphertextToUsers < ActiveRecord::Migration[5.2] +class AddEmailCiphertextToUsers < ActiveRecord::Migration[6.0] def change add_column :users, :email_ciphertext, :text end end ``` @@ -90,18 +108,21 @@ encrypts :properties, type: :json encrypts :settings, type: :hash end ``` -**Note:** Always use a `text` or `binary` column in migrations, regardless of the type +**Note:** Always use a `text` or `binary` column for the ciphertext in migrations, regardless of the type Lockbox automatically works with serialized fields for maximum compatibility with existing code and libraries. ```ruby class User < ApplicationRecord serialize :properties, JSON encrypts :properties + + store :settings, accessors: [:color, :homepage] + encrypts :settings end ``` #### Validations @@ -245,10 +266,16 @@ ```ruby box.decrypt(ciphertext) ``` +Decrypt and return UTF-8 instead of binary + +```ruby +box.decrypt_str(ciphertext) +``` + ## Migrating Existing Data Lockbox makes it easy to encrypt an existing column. Add a new column for the ciphertext, then add to your model: ```ruby @@ -382,24 +409,33 @@ Heroku [comes with libsodium](https://devcenter.heroku.com/articles/stack-packages) preinstalled. ##### Ubuntu -For Ubuntu 16.04, use: +For Ubuntu 18.04, use: ```sh -sudo apt-get install libsodium18 +sudo apt-get install libsodium23 ``` -For Ubuntu 18.04, use: +For Ubuntu 16.04, use: ```sh -sudo apt-get install libsodium23 +sudo apt-get install libsodium18 ``` ##### Travis CI +On Bionic, add to `.travis.yml`: + +```yml +addons: + apt: + packages: + - libsodium23 +``` + On Xenial, add to `.travis.yml`: ```yml addons: apt: @@ -522,11 +558,11 @@ For XSalsa20, use the appropriate [Libsodium library](https://libsodium.gitbook.io/doc/bindings_for_other_languages). ## Migrating from Another Library -Lockbox makes it easy to migrate from another library. The example below uses `attr_encrypted` but the same approach should work for any library. +Lockbox makes it easy to migrate from another library without downtime. The example below uses `attr_encrypted` but the same approach should work for any library. Let’s suppose your model looks like this: ```ruby class User < ApplicationRecord @@ -536,11 +572,11 @@ ``` Create a migration with: ```ruby -class MigrateToLockbox < ActiveRecord::Migration[5.2] +class MigrateToLockbox < ActiveRecord::Migration[6.0] def change add_column :users, :name_ciphertext, :text add_column :users, :email_ciphertext, :text end end @@ -569,11 +605,11 @@ ``` Then remove the previous gem from your Gemfile and drop its columns. ```ruby -class RemovePreviousEncryptedColumns < ActiveRecord::Migration[5.2] +class RemovePreviousEncryptedColumns < ActiveRecord::Migration[6.0] def change remove_column :users, :encrypted_name, :text remove_column :users, :encrypted_name_iv, :text remove_column :users, :encrypted_email, :text remove_column :users, :encrypted_email_iv, :text @@ -637,5 +673,14 @@ - [Report bugs](https://github.com/ankane/lockbox/issues) - Fix bugs and [submit pull requests](https://github.com/ankane/lockbox/pulls) - Write, clarify, or fix documentation - Suggest or add new features + +To get started with development and testing: + +```sh +git clone https://github.com/ankane/lockbox.git +cd lockbox +bundle install +bundle exec rake test +```