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

versa

v1.2.0

Published

Module to provide encryption/decryption profiles.

Downloads

39

Readme

versa

Module to provide encryption/decryption profiles.

Build Status Dependency Status

*** Still awaiting a third-party audit! ***

npm install versa

Usage

Programmatically

Encryption/Decryption Profile Examples

var Versa = require("versa");

/* If you don't set any options (you don't
// have to,) then Versa will fill in what's
// necessary. Versa-generated passwords are
// 2048 bytes long using the randomBytes
// method of the native Crypto module (unless
// you specify the 'size', the minimum is 16
// bits in size with no ceiling limit.)
// Whether you specify the profile or not,
// be sure to back it up for future use!
*/
console.log(new Versa());
// AES-256-CBC with 2048-bit password:
// { algorithm: 'aes-256-cbc',
//   password: <Buffer 8f 35 a0 40 ... > }

console.log(new Versa({"algorithm":"aes128"}));
// AES128 with 2048-bit password:
// { algorithm: 'aes128',
//   password: <Buffer f5 d4 01 97 ... > }

console.log(new Versa({"size":1337}));
// AES-256-CBC with 1337-bit password:
// { algorithm: 'aes-256-cbc',
//   password: <Buffer 28 cf 03 6b ... > }

console.log(new Versa({"size":15}));
// AES-256-CBC with 16-bit password:
// { algorithm: 'aes-256-cbc',
//   password: <Buffer bc 99 fa 4b ... > }

console.log(new Versa({"password":"my application's secret code"}));
// AES-256-CBC with a String password:
// { algorithm: 'aes-256-cbc',
//   password: 'my application\'s secret code' }

console.log(new Versa({"password":new Buffer("my application's secret code")}));
// AES-256-CBC with a Buffer password:
// { algorithm: 'aes-256-cbc',
//   password: <Buffer 6d 79 20 61 ... > }

console.log(new Versa({"password":{"type":"Buffer","data":[109,121,32,97]}}));
// AES-256-CBC with a JSON-parsed Buffer password:
// { algorithm: 'aes-256-cbc',
//   password: <Buffer 6d 79 20 61 > }

Padding Examples

var Versa = require("versa");

/* Using modulus, further obscure your encrypted
// payloads by increasing their byte lengths toward
// an incremented amount. Versa will serialize your
// message within a larger-looking payload of junk
// bytes from Crypto's randomBytes method. When
// decrypting, Versa will parse out and return your
// original message. Because of the serialization and
// parsing approaches, Versa will only decrypt it's
// own encrypted payloads.
*/

var note    = new Versa();
var message = "Hey!.. here's some information!";

var encrypted = note.encrypt(message);
// This results with a 32-bit encrypted buffer. While
// it is encrypted, it can be guessed that the message
// is small.
//   <Buffer f6 aa 95 19 ... >

var hidden = note.hide(message);
// This results with a 528-bit encrypted buffer. Unlike
// 'encrypted' above, it eliminates the ability to guess
// the size or scale of the original message.
//   <Buffer 3d 7f 2a 7a ... >

console.log('%s',note.decrypt(encrypted)); // Hey!.. here's some information!
console.log('%s',note.show(hidden));       // Hey!.. here's some information!
// Both the above decrypt back to the original message,
// but by "hiding" the message, the two instead look
// unrelated.

Pipe Examples

var FS       = require("fs");
var Versa    = require("./");
var resource = new Versa();

/* Here's a simple pipe example, something like
// you'd use with the native Crypto module. Once
// the pipe is done, we save the encryption/
// decryption profile. We won't worry about the
// password used to encrypt/decrypt, we back it
// and its algorithm up somewhere where we can
// access them later. This example writes the
// profile locally (alongside the encrypted file)
// but you can save it wherever is secure for
// you and your application.
*/
FS.createReadStream("LICENSE")
.pipe(resource.encrypt())
.pipe(FS.createWriteStream("LICENSE.encrypted"))
.on("finish",function(){
  
  FS.writeFileSync("LICENSE.encrypted.profile",resource.json());
  
  console.log("Encrypted!");
  
  /* We'll simulate, as in some other application,
  // loading the profile of what we encrypted the
  // license with to decrypt it back. In most cases,
  // if not all, our profile won't be alongside our
  // plaintext or encrypted file, imagine we've
  // loaded back our profile and we need the license
  // next.
  */
  FS.createReadStream("LICENSE.encrypted")
  .pipe(new Versa(JSON.parse(FS.readFileSync("LICENSE.encrypted.profile"))).decrypt())
  .pipe(FS.createWriteStream("LICENSE.decrypted"))
  .on("finish",function(){
    
    console.log("Decrypted!");
    
    FS.unlinkSync("LICENSE.encrypted");
    FS.unlinkSync("LICENSE.encrypted.profile");
    
    console.log("Cleaned up!");
  });
});