GitHub - h2non/jshashes: Fast and dependency-free cryptographic hashing library for node.js and browsers (supports MD5, SHA1, SHA256, SHA512, RIPEMD, HMAC) (original) (raw)

jshashes is lightweight library implementing the most extended cryptographic hash function algorithms in pure JavaScript (ES5 compliant).

The goal is to provide an dependency-free, fast and reliable solution for hash algorithms for both client-side and server-side JavaScript environments. The code is fully compatible with the ECMAScript 5 specification and is used in production in browsers and node.js/io.js

If you are looking for a low-level performance library for the server-side, note that node.js/io.js provides its own native module: crypto

Supported hash algorithms

Additional functionalities

Environments

Usage

Each algorithm has its respective own instantiable object. Here you can see an example of how to create a new instance for each one:

// new MD5 instance var MD5 = new Hashes.MD5 // new SHA1 instance var SHA1 = new Hashes.SHA1 // new SHA256 instance var SHA256 = new Hashes.SHA256 // new SHA512 instace var SHA512 = new Hashes.SHA512 // new RIPEMD-160 instace var RMD160 = new Hashes.RMD160

An example of how to generate an hexadecimal-based hash encoding for each algorithm:

// sample string var str = 'Sample text!' // output to console console.log('MD5: ' + MD5.hex(str)) console.log('SHA1: ' + SHA1.hex(str)) console.log('SHA256: ' + SHA256.hex(str)) console.log('SHA512: ' + SHA512.hex(str)) console.log('RIPEMD-160: ' + RMD160.hex(str))

Browsers

This is a simple implementation for a client-side environment:

node.js / io.js

// require the module var Hashes = require('jshashes') // sample string var str = 'This is a sample text!' // new SHA1 instance and base64 string encoding var SHA1 = new Hashes.SHA1().b64(str) // output to console console.log('SHA1: ' + SHA1)

Command-line interface

You can use the simple command-line interface to generate hashes.

$ hashes sha1-hex This is a sample string

b6a8501d8a70e74e1dc12a6082102622fdc719bb

or with quotes

$ hashes sha1-hex "This is a sample string"

b6a8501d8a70e74e1dc12a6082102622fdc719bb

For more information about the options supported, type:

Installation

Via npm

Via Bower:

Via Component:

$ component install h2non/jshashes

Or loading the script directly:

http://cdn.rawgit.com/h2non/jsHashes/master/hashes.js

Public methods

Each algorithm class provides the following public methods:

Hash encoding formats supported

Benchmark

Node.js 0.6.18 running on a VPS Intel I7 930 with 512 MB of RAM (see server/benchmark.js)

Simple benchmark test generating 10000 hashes for each algorithm. String: "A0gTtNtKh3RaduBfIo59ZdfTc5pTdOQrkxdZ5EeVOIZh1cXxqPyexKZBg6VlE1KzIz6pd6r1LLIpT5B8THRfcGvbJElwhWBi9ZAE"

See client/benchmark.html for client-side.

Notes

Changelog

TODO

Authors

Library author

Original algorithm authors

Other contributors

License

jsHashes is released under New BSD license. See LICENSE file.

Issues

Feel free to report any issue you experiment via Github https://github.com/h2non/jsHashes/issues.