Code Monkey home page Code Monkey logo

encrypted's Introduction

Encrypted is a simple monadic data type that wraps arbitrary data for asymmetric encryption. It provides map and flatMap functions to apply operations on the payload.

Usage

First you need to generate key pairs for all involved parties:

import com.github.greywombat.encrypted._

val alice = KeyPair("alice")
val bob = KeyPair("bob")
val eve = KeyPair("eve")

Then, you can set up a key store for the public keys of all members and declare one private key as your own:

implicit val publicKeyStore: PublicKeyStore = KeyStore().addKey(alice).addKey(bob).addKey(eve)
implicit val privateKey: PrivateKey = alice

Afterwards you can use it:

val enc: Encrypted[String] = Encrypted("Secret data")

Note that it is not actually encrypted yet, to do

val enc = Encrypted("Secret data").encrypt

To limit access to the data, you can apply a set of client ids:

val enc = Encrypted("Secret data").restrict(Set("alice", "bob")).encrypt

You can access the payload by calling get (optionally with a private key):

// Some("Secret data")
enc.get

// None
enc.get(eve.privateKey)

Encrypted values can be mapped over:

// Some("Secret data. And more secret data.")
enc.map(_ + ". And more secred data.").get

Or, used in a list comprehension:

val enc2 = for(
    a <- enc;
    b <- Encrypted(". And more secret data.").restrict(Set("alice"))
  ) yield a + b

// Some("Secret data. And more secret data.")
enc2.get

// None
enc2.get(bob)

When doing this the resulting encrypted container only allows access for parties that have access to all data that was involved in creating the new data.

encrypted's People

Watchers

 avatar

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.