Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

encrypt_column

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encrypt_column

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Gem Version Build Status Coverage Status Issue Count Code Climate

EncryptColumn

Encrypt any column with an optional hash (using searchable: true) or conditionally (if: Proc) also has a failsafe (failsafe: true) feature to write to different db column in the database, i.e. <name>_ciphertext. This prevents users from accidentally commenting out the encrypt declaration and writing plaintext to the database.

Installation

Add this line to your application's Gemfile:

gem 'encrypt_column'

And then execute:

$ bundle

Or install it yourself as:

$ gem install encrypt_column

Usage

Specify the column to be encrypted as so (i.e. encrypt ssn column):

  encrypt :ssn

To add a <Model>.with_<field_name>(<field_value>) search method (using a hash column named <column_name>_hash or ssn_hash)

  encrypt :ssn, searchable: true

Usage like so:

  SecureTable.with_ssn('123456789')

To use a failsafe column name to prevent accidental removal of encryption specify "failsafe: true". This will store the data in a column name <column_name>_ciphertext (i.e. ssn_ciphertext) but allow for read/write access by the original column name.

  encrypt :ssn, failsafe: true

To conditionally encrypt a column you can specify an if statement like so:

  encrypt :card_number,  if: -> (x) { x.card_type == 'credit' }

Use all the options combined, like so:

  encrypt :card_number, searchable: true, failsafe: true, if -> (x) { x.card_type == 'credit' }

The gem uses the ENCRYPTION_KEY environment variable for encryption setup:

  ENV['ENCRYPTION_KEY'] = 'your_encryption_key_goes_here'

Alternatively, you can specify the encryption key as an option in the encrypt line:

  encrypt :ssn, key: 'your_encryption_key_goes_here'

and optionally a HASH_SALT if the searchable option is used.

  ENV['HASH_SALT'] = 'some_salt'

Or specify the hash salt in the encrypt line:

  encrypt :ssn, :searchable, hash_salt: 'your_hash_salt_goes_here', key: 'your_encryption_key_goes_here'

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/danlherman/encrypt_column.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 11 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc