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

simple-encryption

v1.0.1

Published

Simple encryption using node-forge as the library to encrypt

Downloads

19

Readme

simple-encryption

CircleCI NPM Version NPM Download

Simple encryption module for NodeJS using node-forge

Installation

npm install simple-encryption

Usage

Importing

At the top of your code, use something like this to import simple-encryption

var sencrypt = require('simple-encryption');

Or alternatively, for ease of use, you could do this:

var RSA = require('simple-encryption').RSA;
var AES = require('simple-encryption').AES;

RSA

Currently, RSA is just the basics: encrypting, decrypting, signing, and verifying

Encryption

var RSA = require('simple-encryption').RSA;
var publicKey; //Normally you'd need to assign this variable a PEM encoded public key
var privateKey; //Normally you'd need to assign this variable a PEM encoded private key
var encrypted = RSA.encrypt(publicKey, 'Hello, World!'); //Encrypts Hello, World and outputs it as Base64
var decrypted = RSA.decrypt(privateKey, encrypted); //Decrypts the message
console.log(encrypted);
console.log(decrypted);

Signing

var RSA = require('simple-encryption').RSA;
var publicKey; //Normally you'd need to assign this variable a PEM encoded public key
var privateKey; //Normally you'd need to assign this variable a PEM encoded private key
var signed = RSA.sign(privateKey, 'Hello, World!'); //Sign the message Hello, World
var verified = RSA.verify(publicKey, signed.signed, signed.md); //Verify the message with the base64 message signature and base64 message digest returned from the previous function
if(verified) {
  //verified is a boolean, true on if verification was successful, and false when it wasn't
  console.log("Verification successful");
} else {
  console.log("Verification failed");
}

Notes

  • You need to generate your own keys, and they should be in a PEM format
  • Any potential binary outputs (encrypted/signed outputs) are encoded in base64 to reduce errors

AES

Notes

  • AES uses AES-GCM. If you need another mode, this module is currently not for you

Generating information needed

var AES = require('simple-encryption').AES;
var iv = AES.generateIV(); //Generate 12 byte IV. Outputs Base64
var iv2 = AES.generateIV(16); //Is also valid and generates a 16 byte IV, but AES-GCM requires a 12 bytes IV. Outputs Base64
var key = AES.generateKey(); //Generate a 256 bit (32 byte) key. Outputs Base64
var key2 = AES.generateKey(16); //Generate a 128 bit (16 byte) key. Outputs Base64.

Encryption

var AES = require('simple-encryption').AES;
var iv = AES.generateIV();
var key = AES.generateKey();
var encrypted = AES.encrypt(key, iv, 'Hello, World!'); //Encrypts 'Hello, World!', outputting a JavaScript object with Base64 properties
var decrypted = AES.decrypt(key, iv, encrypted.tag, encrypted.encrypted); //Decrypts 'Hello, World!', and also verifies it at the same time
if(decrypted) {
  //If authentication was successful (i.e. it comes from the same person)
  console.log("Auth successful: " + decrypted);
} else {
  //Someone has tampered with it
  console.log("Auth failed");
}

License

ISC