npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

alice-crypto

v1.2.0

Published

Cryptographic message exchanging protocol

Downloads

9

Readme

Alice

Cryptografic message exchanging protocol based on RSA and AES.

Installation

$ npm install alice-crypto --save

Usage

const Alice = require('alice-crypto');

const alice = new Alice();
const bob = new Alice();

const secretMessage = 'Cats are cool, but dogs are better!';

// Only Bob can decipher the contents of this message.
// May be sent over insecure channels.
const cipheredMessage = alice.write(secretMessage, bob.pubkey);

const decipheredMessage = bob.read(cipheredMessage);

assert(decipheredMessage === secretMessage);

API

new Alice(options)

Returns a new instance of Alice.

Note: It may take a few seconds to generate the RSA keypair, which is a blocking operation. It is recommended to create the new instance as a singleton during your app's initialization routine.

options Object

rsaKeyBits Integer: Length of the RSA keypair. Default: 2048.

aesAlgorithm String: AES algorithm to pass to node's crypto.createCipheriv and crypto.createDecipheriv functions. Default: "aes256".

aesKeyBytes Integer: Length of the AES key to be randomly generated with each encryption. Default: 32.

aesIvBytes Integer: Length of the AES initialization vector to be randomly generated with each encryption. Default: 16.

instance.pubkey

The public key string to be shared between instances of Alice over insecure channels.

instance.write(message String, pubkey String, [sign Boolean])

Returns an object that can be sent over insecure channels to the owner of pubkey. If sign is set to true, will include signature.

instance.read(ciphered Object, [pubkey String])

Returns a string containing the original message. If pubkey is present, will verify the signature of the message and throw an error if invalid.

Example server usage

This sample would allow two servers running instances of Alice to communicate securely over open channels.

const Alice = require('alice-crypto');
const express = require('express');
const bodyParser = require('body-parser');
const request = require('request');

const alice = new Alice();

const app = express();
app.use(bodyParser());

const thisHostname = 'alice.example.com';
const bobHostname = 'bob.example.com';

const importantMessage =
  'Bob, my bank account password is 123456. Nobody else must know!';

function sendMessage (message, hostname) {
  request(`http://${hostname}/pubkey`, (err, response, body) => 
    const pubkey = body;
    const ciphered = alice.write(message, pubkey);

    request.post(`http://${hostname}/secret-message`,
      { form: { message: JSON.stringify(ciphered) } });
  );
}

app.get('/pubkey', (req, res, next) => {
  res.send(alice.pubkey);
}

app.post('/secret-message', (req, res, next) => {
  const ciphered = JSON.parse(req.body.message);
  const message = alice.read(ciphered);

  console.log(message);
}

app.listen(80);

sendMessage(importantMessage, bobHostname);

License

MIT