Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
A fast and independent hashing library pure JavaScript implemented (ES3 compliant) for both server and client side (MD5, SHA1, SHA256, SHA512, RIPEMD, HMAC and Base64)
A fast and independent hashing library pure JavaScript implemented for both server and client side
jsHashes
is a pure JavaScript implementation of the most extended hash algorithms.
Its goal is to provide an independent, fast and easy solution for hash algorithms both for client-side and server-side JavaScript environments.
The code is fully compatible with the ECMAScript language specification version 3 and was tested in all major browsers (client-side) and node.js (server-side).
If you are looking for a high low-level performance on the server-side, note that Node.js provides its own C++ native module (Crypto).
MD5
(http://www.ietf.org/rfc/rfc1321.txt)SHA1
(http://www.itl.nist.gov/fipspubs/fip180-1.htm)SHA256
(http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf)SHA512
(http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf)HMAC
(http://www.ietf.org/rfc/rfc2104.txt)RIPEMD-160
(http://homes.esat.kuleuven.be/~bosselae/ripemd160.html)Aditional functionalities
Base64 encoding/decoding
(http://tools.ietf.org/html/rfc3548)CRC-32 calculation
UTF-8 encoding/decoding
Following some software design patterns, jsHashes
implements an object-oriented class-based paradigm for an easy and clean use.
Each algorithm has its respective own class
, providing encapsulation and low coupling between classes.
Here you can see an example of how to create a new instance for each algorithm:
// 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;
Now, an example of how to output an hexadecimal-based hash encoding for each algorithm (client-side):
// 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));
This is a simple implementation for a client-side environment:
<html>
<head>
<script type="text/javascript" src="src/hashes.js"></script>
<script type="text/javascript">
// sample string
var str = 'This is a sample text!';
// new MD5 instance and hexadecimal string encoding
var MD5 = new Hashes.MD5().hex(str);
// output into DOM
document.write('<p>MD5: <b>' + MD5 + '</b></p>');
</script>
</head>
<body>
</body>
</html>
The library is based on CommonJS module standard, so the same code works in Node and other environments.
jsHashes
is available via NPM. You can install it simply doing:
$ npm install jshashes
Additionally, you can get jsHashes using Bower or Jam package managers.
$ bower install jshashes
$ jam install jshashes
A Node.js example:
// 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);
Each algorithm 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 this
Object.setUpperCase(boolean)
- Enable/disable uppercase hexadecimal returned string. Returns this
Object.setPad(string)
- Defines a custom base64 pad string. Default is '=' according with the RFC standard. Returns this
Object.setUTF8(boolean)
- Enable/disable UTF-8 character encoding. Returns this
Object.any()
methodNode.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"
* 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
See client/benchmark.html
for client-side.
jsHashes
in other server-side JS environment.1.0.3
1.0.2
1.0.1
0.1.5b
0.1.4b
0.1.3b
Helpers
Object with some global functionsclass
0.1.2b
0.1.1b
0.1.0b
jsHashes is released under New BSD
license. See LICENSE
file.
Feel free to report any issue you experiment via Github https://github.com/h2non/jsHashes/issues.
FAQs
A fast and independent hashing library pure JavaScript implemented (ES3 compliant) for both server and client side (MD5, SHA1, SHA256, SHA512, RIPEMD, HMAC and Base64)
The npm package jshashes receives a total of 22,276 weekly downloads. As such, jshashes popularity was classified as popular.
We found that jshashes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.