GithubHelp home page GithubHelp logo

cianmce / master-crypt Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 42 KB

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

License: MIT License

Ruby 99.01% Shell 0.99%
encryption cryptography ruby

master-crypt's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.