2.0.0 • Published 6 years ago

ppc-messaging v2.0.0

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
6 years ago

PPC-Messaging

Tiny library to facilitate public/private key crypto and use it for encrypted messaging between hosts using node.js.

Usage

Embed the library and use the below methods. For an example, see example.js, or run npm run test to see it in action. You can use npm run generate-keys to generate RSA public-private key pairs.

Methods

encryptMessage(clientId, publicKey, message)

Encrypts the message using the provided public key. Embeds secret clientId in the message, which is used by the server to encrypt its response. Returns an object, with contents exposing the ciphertext, and message_id the generated internal message id.

Example:

const ppc = require("ppc-messaging")

let msg = ppc.encryptMessage(cid, pubkey, {
  redirect_to: "https://notes.skylark.ee/auth"
})

console.log("Encrypted message:", msg.contents)
console.log("Message ID:", msg.message_id)

decryptMessage(privateKey, message)

Possessing the private key decrypts the encrypted message.

Example:

const ppc = require("ppc-messaging")

let decmsg = ppc.decryptMessage(privkey, ciphertext)

console.log("Decrypted message:", decmsg)

encryptResponse(messageId, clientId, message)

Creates an encrypted response, in reply to the specified messageId. It uses the supplied clientId to encrypt the message.

Example:

const ppc = require("ppc-messaging")

let resp = ppc.encryptResponse(decmsg.msg_id, decmsg.client_id, {
  session_id: sid
})

console.log("Encrypted response:", resp)

function decryptResponse(clientId, message)

Decrypts a received response using the supplied clientId.

Example:

const ppc = require("ppc-messaging")

let decresp = ppc.decryptResponse(cid, resp)

console.log("Decrypted response:", decresp)
2.0.0

6 years ago

1.0.0

6 years ago