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:
Supported hash algorithms
- Browsers (ES3)
- node.js/io.js (all versions)
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 instancevar MD5 =// new SHA1 instancevar SHA1 =// new SHA256 instancevar SHA256 =// new SHA512 instacevar SHA512 =// new RIPEMD-160 instacevar RMD160 =
An example of how to generate an hexadecimal-based hash encoding for each algorithm:
// sample stringvar str = 'Sample text!'// output to consoleconsoleconsoleconsoleconsoleconsole
This is a simple implementation for a client-side environment:
node.js / io.js
// require the modulevar Hashes =// sample stringvar str = 'This is a sample text!'// new SHA1 instance and base64 string encodingvar SHA1 =// output to consoleconsole
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:
$ hashes -h
$ npm install jshashes
$ bower install jshashes
$ component install h2non/jshashes
Or loading the script directly:
class provides the following public methods:
hex(string)- Hexadecimal hash encoding from string.
b64(string)- Base64 hash encondig from string.
any(string,encoding)- Custom hash algorithm values encoding.
hex_hmac(key,string)- Hexadecimal hash with HMAC salt key.
b64_hmac(key,string)- Base64 hash with HMAC salt key.
any_hmac(key,string,encoding)- Custom hash values encoding with HMAC salt key support.
vm_test()- Simple self-test to see is working. Returns
setUpperCase(boolean)- Enable/disable uppercase hexadecimal returned string. Returns
setPad(string)- Defines a custom base64 pad string. Default is '=' according with the RFC standard. Returns
setUTF8(boolean)- Enable/disable UTF-8 character encoding. Returns
Hash encoding formats supported
- Hexadecimal (most extended)
- Custom hash values
Node.js 0.6.18 running on a VPS Intel I7 930 with 512 MB of RAM (see
Simple benchmark test generating 10000 hashes for each algorithmString: "A0gTtNtKh3RaduBfIo59ZdfTc5pTdOQrkxdZ5EeVOIZh1cXxqPyexKZBg6VlE1KzIz6pd6r1LLIpT5B8THRfcGvbJElwhWBi9ZAE"* MD5** Done in: 205 miliseconds* SHA1** Done in: 277 miliseconds* SHA256** Done in: 525 miliseconds* SHA512** Done in: 593 miliseconds* RMD160** Done in: 383 miliseconds
client/benchmark.html for client-side.
- Don't support checksum hash for files on the server-side, only strings-based inputs are supported.
- It has not been planned to include support for more hash algorithms.
- Only Node.js server-side was tested, so with minimal changes, you can setup
jsHashesin other server-side JS environment.
- Merge #37: fix terminator statement token.
- Fix #34: options
- Fix #34: options
- Fix CLI script call error when use it from Bash
- Added CLI usage example
- Important bugfixes to UTF-8 encoding (broken in 1.0.2) and the RIPEMD-160 hash (broken in 1.0.1). (gh #6)
- New test suite for hashes, CRC32, and hmac; run with 'npm test' in node.
- Fixed global variable leaks. (gh #13)
- CRC32 will now always return positive values. (gh #11)
- Added package version property to the exposed Hashes Object
- Updated CLI script utility supporting all algorithms (see bin/hashes)
- Fixed UTF-8 encoding/decoding error (if input parameter is undefined or invalid)
- Performance improvements and minimal refactor (length property caching, literal notation)
- Available from Bower package manager
- Refactoring (hoisting, coercion, removed redundant functions, scoping, restructure...)
- Performance improves
- JSLint validation (except bitwise operators)
- Now the library can be used like a AMD CommonJS module
- Updated documentation
- New folders structure
- Added closure compiled and minimized library version
- Available from Jam package manager
- Added index.js for easy call the module in Node.js
- Updated documentation
- Now declaring objects using Literal Notation.
- Solved sintax errors on minimized version (jshashes.min.js)
- Added benchmark test and sample
- Starting non-redundancy code refactorization
HelpersObject with some global functions
- Added native support for Base64 provided as
- Added CRC-32 calculation support
- Added URL encode/decode helpers functions
- SHA1 error fixed.
- General code changes (renaming classes, private methods, new methods...).
- Changing library namespace to 'Hashes'.
- Starting code documentation.
- Added new examples of how to use.
- Minimal library improvements.
- There has been added some samples, like how to use it and support for NPM package.
- First release: the code is stable, but the library is still beta and must be improved and documented.
- Performance benchmarking
Original algorithm authors
- Paul Johnston
- Angel Marin (SHA256)
- Jeremy Lin (RIPEMD-160)
- C. Scott Ananian
- Greg Holt
- Andrew Kepert
jsHashes is released under
New BSD license. See
Feel free to report any issue you experiment via Github https://github.com/h2non/jsHashes/issues.