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

crypto-toolkit

v1.1.1

Published

A set of utility functions/wrapper to simplify the development workflow

Downloads

136

Readme

Crypto-Toolkit

DEPRECATED

superseded by crypto-magic


A set of utility functions/wrapper to simplify the development workflow

$ npm install crypto-toolkit

Features

  • Hash Function Wrapper (MD5, SHA1, SHA244, SHA256, SHA384, SHA512, WHIRLPOOL)
  • Create Object/Array Hashes based on its JSON representation

Hash Function Wrapper

Provides easy access to the Node.js Crypto Hash functions. Examples are available in examples/hash.js

// default hex encoding
var _hash = require('crypto-toolkit').Hash('hex');

console.log(_hash.sha256('Hello World'));
Initialization
require('crypto-toolkit').Hash([encoding:string])

The argument encoding is optional and defines the output encoding of the digest.

  • hex (default) - hexadecimal string output
  • base64 - base64 string output
  • base64-urlsafe - url-safe base64 string output (/+= are replaced by _-)
  • binary - binary output as Buffer
Hash Algorithms

The following wrappers are included:

  • md5(input:mixed, [encoding:string])
  • sha1(input:mixed, [encoding:string])
  • sha2(input:mixed, [encoding:string])
  • sha224(input:mixed, [encoding:string])
  • sha256(input:mixed, [encoding:string])
  • sha384(input:mixed, [encoding:string])
  • sha512(input:mixed, [encoding:string])
  • whirlpool(input:mixed, [encoding:string])

General Usage

var _hash = require('crypto-toolkit').Hash('hex');

// some input
var input = 'Hello World';

// display some hashes
console.log('Default HEX Output');
console.log(' |- MD5      ', _hash.md5(input));
console.log(' |- SHA1     ', _hash.sha1(input));
console.log(' |- SHA256   ', _hash.sha256(input));
console.log(' |- SHA384   ', _hash.sha384(input));
console.log(' |- SHA512   ', _hash.sha512(input));
console.log(' |- WHIRLPOOL', _hash.whirlpool(input));

// override the default output type
console.log('Override the default output settings');
console.log(' |- HEX      ', _hash.sha1(input, 'hex'));
console.log(' |- BIN      ', _hash.sha1(input, 'binary'));
console.log(' |- BASE64   ', _hash.sha1(input, 'base64'));
console.log('');

Objects

Objects/Arrays are automatically serialized as JSON String. The JSON object is then passed into the hash function.

var _hash = require('crypto-toolkit').Hash('hex');

// demo object
var objectInput = {
    x: 1,
    b: 2,
    c: [5,6,7],
    d: {
        y: 'Hello',
        z: 'World'
    }
};

console.log('Object Input');
console.log(' |- SHA256   ', _hash.sha256(objectInput));
console.log('');

Random Hash Generator

Create random hashes easily. Just calls the crypto-toolkit.Hash functions with a random content generated by crypto.randomBytes(514) - helpful for random URLs or filenames (e.g. cache hashes).

// url-safe base64
var _randomhash = require('crypto-toolkit').RandomHash('base64-urlsafe');

// all hash function of crypto-toolkit.Hash are supported
console.log(_randomhash.sha256());

// output like b7qhqd-WnKAH_GmBpSpvQrdkfUdLxL0m__XGcLTRsbI

Any Questions ? Report a Bug ? Enhancements ?

Please open a new issue on GitHub

License

Crypto-Toolkit is OpenSource and licensed under the Terms of The MIT License (X11). You're welcome to contribute!