sha.js
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
inherits | 2.0.4 | 1.98 kB | ISC | prod | |
safe-buffer | 5.2.1 | 9.74 kB | MIT | prod |
Sha.js is a node-style, pure JavaScript implementation of the Secure Hash Algorithm (SHA). It provides streamable SHA hashes, allowing for incremental updates and enabling it to easily handle data larger than your available memory. Please note that some older versions of the algorithm, SHA-0 and SHA-1, are now considered to be legacy and their use in new systems is discouraged. However, sha.js also supports SHA-224, SHA-256, SHA-384, and SHA-512, catering for the needs of modern applications.
To use sha.js, you first need to import it into your project. You can do so by using the require
function which is built into Node.js. Once you have imported sha.js, you can call it with the name of the hashing algorithm you wish to use, update it with the data you want to hash and then produce the hash with the digest
method. Here is an example:
var shajs = require('sha.js')
console.log(shajs('sha256').update('42').digest('hex'))
// this will output: 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049
In this example, 'sha256'
is the hashing algorithm being used, '42'
is the data being hashed, and 'hex'
is the format of the resulting hash. Sha.js can also be used in a more object-oriented style. Here is an example of that:
console.log(new shajs.sha256().update('42').digest('hex'))
// this will output the same hex string hash as in the previous example
The documentation for sha.js does not appear to be hosted on a separate webpage. Instead, users are directed to the library's GitHub page at https://github.com/crypto-browserify/sha.js for more information. This readme file itself includes details on basic usage and supported hashing algorithms, as well as disclosing that it does not itself actually implement a stream. For those looking for a streamable interface, the readme suggests that it would be trivial to wrap sha.js in a stream. It also credits the work from which sha.js is derived and provides licensing details.