Skip to content

Master Key is a gem for encrypting data with multiple keys that can be decrypted with any of them

License

Notifications You must be signed in to change notification settings

cianmce/master-crypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Master Crypt

CircleCI Gem Version

Master Key is a gem for encrypting data with a master keying approach meaning you can encrypt data with multiple keys and then decrypt it any of them

This allows you to have a master key to decrypt the full set of data while also creating keys that can only decrypt a subset of data. These keys can then be safely distributed to relevant actors who will be only able to access their permitted data

You can encrypt data with as many keys as needed, all of which will be able to decrypt the data while only causing a small encrypted data size increase of 129 bytes for each extra key

Installation

Installing RbNaCl

https://github.com/RubyCrypto/rbnacl#installation

OS X users

brew install libsodium

FreeBSD users

pkg install libsodium

APT users

apt install libsodium-dev

Installing MasterCrypt

gem install master_crypt

Usage

Encrypting data with a master key

require "master_crypt"

master_key = "Very secure & random master k3y"
other_secret_key = "Another very secure & random other k3y"
plaintext = "Secret data..."
master_crypt = MasterCrypt.new(master_key)

encrypted_data = master_crypt.master_key_encrypt(plaintext, [other_secret_key])
# encrypted_data can be decrypted with either the master_key or other_secret_key

Decrypting data with a master key

master_key = "Very secure & random master k3y"
encrypted_data = "...."
master_crypt = MasterCrypt.new(master_key)

plaintext = master_crypt.master_key_decrypt(encrypted_data)

Encrypting data with an array of keys

secret_keys = ["array", "of", "secret", "keys"]
encrypted_data = MasterCrypt.encrypt(plaintext, secret_keys)

Decrypting data with a specific key

MasterCrypt.decrypt(encrypted_data, secret_keys[0])

Development

bundle install

Run all specs + standardrb

bundle exec rake

Run specs using guard

bundle exec guard

About

Master Key is a gem for encrypting data with multiple keys that can be decrypted with any of them

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published