Giter Site home page Giter Site logo

zhoumingchun / secure-key-exchange Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pubnub/secure-key-exchange

0.0 1.0 0.0 1.02 MB

Babel - Encrypted Self Destructing Messaging with Asymmetric Key Exchange Public-Private Crypto.

License: MIT License

CSS 2.26% JavaScript 67.56% HTML 30.18%

secure-key-exchange's Introduction

Babel

Key Exchange and Self-Destructing Messages with PubNub

Babel is an open source chat widget and API built with the PubNub Global Realtime Network. With Babel you can exchange 1024-bit RSA Public Keys, and send Encrypted, Self-Destructing Messages.


Source Walkthrough

###Check out the annotated source.


API Walkthrough

1. First Steps

Babel uses both PubNub and Cryptico. So first, let's include the all the necessary libraries. We can then instantiate a Babel object by calling Babel with a username string.

<script src="http://cdn.pubnub.com/pubnub.min.js"></script>

<!-- Download both from https://github.com/lw7360/babel -->
<script src="./cryptico.js"></script> 
<script src="./babel.js"></script>

<script> 
    var doge = new Babel('doge'); // Initialize Babel with a username
</script>

2. Public Key Exchange

listUsers() returns an object with all currently connected users' usernames and their public keys.

console.log(doge.listUsers());
// {username: publicKey}
// {doge: "olpbSlUEca0VVVqcs9ciUZyP...NNIkqx9lVtUZDYLUWhnjaNrEK4E="}

myKey() returns your Cryptico RSA key.

3. Encrypted Self-Destructing Messages

sendMessage(recipient, message, ttl) encrypts message with recipient's public key, and sends the encrypted message to recipient. The message will be accessible through the returnMessages method for both you and the recipient for ttl seconds.

doge.sendMessage('shibe', 'Very greetings shibe. Much Excited!', 5);
// This will send a message to 'shibe', with the message 
// 'Very greetings shibe. Much Excited!'. 
// Both you and `shibe` will only be able to view this message for 5 seconds.

returnMessages() returns all the messages you've sent or received that have yet to time out.

console.log(doge.returnMessages());
// {
//   shibe: [
//	   {
//       TTL: 5,
//       msgID: "2fa4abf3-08d4-4e40-873f-f35540590d04",
//       plaintext: "Very greetings shibe. Much Excited!",
//       recipient: "shibe",
//       sender: "doge"
//     }
//   ]
// }

onMessage(callback) let's you set a function to be called whenever you receive or send a message.

var	messageHandler = function(msg) {console.log(msg);};
doge.onMessage(messageHandler);

// 'shibe' responds to our earlier message and sends us a message of his own.
// messageHandler would be called and would print the following.
// {
//     msgID: "d8fd0f29-81cf-4c35-8aef-59b2c664628f", 
//     plaintext: "Much hello doge!  Very cannot wait.", 
//     TTL: 5, 
//     sender: "shibe", 
//     recipient: "doge"
// }
// msgID is a unique string that can be used to identify the message.

onPresence(callback) does the same thing for presence events, i.e. users joining/leaving/timing out of the channel.

quit() causes you to leave the channel. Other users will no longer be able to retrieve your public key or send messages to you.

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.