Giter VIP home page Giter VIP logo

ee2ee's Introduction

This was a learning experience

EE2EE

Easy End 2 End Encryption

This is just me learning, I wouldn't use this for anything.

[1.a] Init (Orgin)

Import node's crypto module and the EE2EE module. Since we didn't provide any shared public key, EE2EE will generate one for us, also, it will automatically generate Bob's public key.

import { EE2EE } from './main';

let bob = new EE2EE();

// Shared Public key //
console.log(bob.sharedPublicKey);

// Bob's public key // 
console.log(bob.aPublicKey);

[1.b] Init (Client)

Import node's crypto module and the EE2EE module. Since we reciveing, we will define the Orgin's Shared Public key and their Public key

import { EE2EE } from './main';

let alice = new EE2EE(sharedPublicKey, aPublicKey);

// Shared Public key //
console.log(alice.sharedPublicKey);

// Alice's public key // 
console.log(alice.aPublicKey);

[2.a] Getting the shared private key (Orgin)

Once you recive the Client's (B) public key, you'll be able to define it, and generate Bob's shared private key.

bob.bPublicKey = clientPublicKey;

// generate the shared private key
let sharedPrivateKey = bob.getSharedPrivateKey();

// the private key that both parties have
console.log(sharedPrivateKey);

[2.b] Getting the shared private key (Client)

Since you've already recived all the required keys to generate your private shared key, it's automatically generated for you.

// generate the shared private key
let sharedPrivateKey = alice.getSharedPrivateKey();

// the private key that both parties have
console.log(sharedPrivateKey);

Encrypt and Decrypt some data!

Now that you have generated the shared private keys, you can use the internal encrypt, encryptCompact, decrypt and decryptCompact functions.

//Encrypt takes in a strign as its only paramater

let encrypted = bob.encrpyt('hello world!');
//We have just encrypted 'hellow world' with the shared private key
//this will return and object containing the encrypted Data, Iv and Tag
//{
//    content: encrypted,
//    tag: tag64,
//    iv: iv64,
//};

// You can then decrypt it, we will use Alice for this example
let decrypted = alice.decrypt(encrypted.content, encrypted.tag, encrypted.iv);

//if we print this, we should see 'hello world!'
console.log(decrypted);

or

//You can just format everything into one string using 'encryptCompact'

let encrypted = bob.encryptCompact('hello world!');
//This will return a string, formated as such 'encryptedData.tag.iv'
//Encoded in Base64

//You can than just take that formated string, and decrypt it with 'decryptCompact'
let decrypted = alice.decryptCompact(encrypted);

//if we print this, we should see 'hello world!'
console.log(decrypted);

Demo code

import { EE2EE } from './main';

let bob = new EE2EE(),
    bPub = bob.aPublicKey;

let alice = new EE2EE(bob.sharedPublicKey, bPub);

bob.bPublicKey = alice.aPublicKey;

bob.getSharedPrivateKey();
alice.getSharedPrivateKey();

let encrypted = bob.encryptCompact('Hello World!');
console.log(encrypted);

let decrypted = alice.decryptCompact(encrypted);
console.log(decrypted);

ee2ee's People

Contributors

grzegorzmaniak avatar

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.