Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 20-Jan-2022 | - | ||||
node_modules/readable-stream/ | H | 20-Jan-2022 | - | 155 | 119 | |
LICENSE | H A D | 20-Jan-2022 | 1.1 KiB | 22 | 17 | |
README.md | H A D | 20-Jan-2022 | 1.7 KiB | 49 | 34 |
README.md
1# hash-base 2 3[![NPM Package](https://img.shields.io/npm/v/hash-base.svg?style=flat-square)](https://www.npmjs.org/package/hash-base) 4[![Build Status](https://img.shields.io/travis/crypto-browserify/hash-base.svg?branch=master&style=flat-square)](https://travis-ci.org/crypto-browserify/hash-base) 5[![Dependency status](https://img.shields.io/david/crypto-browserify/hash-base.svg?style=flat-square)](https://david-dm.org/crypto-browserify/hash-base#info=dependencies) 6 7[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) 8 9Abstract base class to inherit from if you want to create streams implementing the same API as node crypto [Hash][1] (for [Cipher][2] / [Decipher][3] check [crypto-browserify/cipher-base][4]). 10 11## Example 12 13```js 14const HashBase = require('hash-base') 15const inherits = require('inherits') 16 17// our hash function is XOR sum of all bytes 18function MyHash () { 19 HashBase.call(this, 1) // in bytes 20 21 this._sum = 0x00 22} 23 24inherits(MyHash, HashBase) 25 26MyHash.prototype._update = function () { 27 for (let i = 0; i < this._block.length; ++i) this._sum ^= this._block[i] 28} 29 30MyHash.prototype._digest = function () { 31 return this._sum 32} 33 34const data = Buffer.from([ 0x00, 0x42, 0x01 ]) 35const hash = new MyHash().update(data).digest() 36console.log(hash) // => 67 37``` 38You also can check [source code](index.js) or [crypto-browserify/md5.js][5] 39 40## LICENSE 41 42MIT 43 44[1]: https://nodejs.org/api/crypto.html#crypto_class_hash 45[2]: https://nodejs.org/api/crypto.html#crypto_class_cipher 46[3]: https://nodejs.org/api/crypto.html#crypto_class_decipher 47[4]: https://github.com/crypto-browserify/cipher-base 48[5]: https://github.com/crypto-browserify/md5.js 49