Private-Public Crypto Messaging
npm install ppc-messagingnode.js.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.
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:
``javascript
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:
`javascript
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:
`javascript
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:
`javascript
const ppc = require("ppc-messaging")
let decresp = ppc.decryptResponse(cid, resp)
console.log("Decrypted response:", decresp)
``