5 <img width="380" src="https://rawgit.com/sindresorhus/hasha/master/media/logo.svg" alt="hasha">
13 > Hashing made simple. Get the hash of a buffer/string/stream/file.
15 [![Build Status](https://travis-ci.org/sindresorhus/hasha.svg?branch=master)](https://travis-ci.org/sindresorhus/hasha)
17 Convenience wrapper around the core [`crypto` Hash class](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm) with simpler API and better defaults.
23 $ npm install --save hasha
30 var hasha = require('hasha');
33 //=> 'e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27'
37 var hasha = require('hasha');
39 // hash the process input and output the hash sum
40 process.stdin.pipe(hasha.stream()).pipe(process.stdout);
44 var hasha = require('hasha');
46 // get the MD5 hash of an image
47 hasha.fromFile('unicorn.png', {algorithm: 'md5'}).then(function (hash) {
49 //=> '1abcb33beeb811dca15f0ac3e47b88d9'
56 See the Node.js [`crypto` docs](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm) for more about hashing.
58 ### hasha(input, [options])
64 Type: `buffer`, `string`, `array` of `string`|`buffer`
66 Buffer you want to hash.
68 While strings are supported you should prefer buffers as they're faster to hash. Though if you already have a string you should not convert it to a buffer.
70 Pass an array instead of concatenating strings and/or buffers. The output is the same, but arrays do not incur the overhead of concatenation.
78 Values: `hex`, `base64`, `buffer`, `binary`
80 Encoding of the returned hash.
86 Values: `md5`, `sha1`, `sha256`, `sha512`, etc *([platform dependent](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm))*
88 *The `md5` algorithm is good for [file revving](https://github.com/sindresorhus/rev-hash), but you should never use `md5` or `sha1` for anything sensitive. [They're insecure.](http://googleonlinesecurity.blogspot.no/2014/09/gradually-sunsetting-sha-1.html)*
90 ### hasha.stream([options])
92 Returns a [hash transform stream](https://nodejs.org/api/crypto.html#crypto_class_hash).
94 ### hasha.fromStream(stream, [options])
96 Returns a promise that resolves to a hash.
98 ### hasha.fromFile(filepath, [options])
100 Returns a promise that resolves to a hash.
102 ### hasha.fromFileSync(filepath, [options])
109 - [Hasha: A Friendly Crypto API • DailyJS](http://dailyjs.com/2015/06/12/hasha-a-friendly-crypto-api/)
114 - [hasha-cli](https://github.com/sindresorhus/hasha-cli) - CLI for this module
115 - [hash-obj](https://github.com/sindresorhus/hash-obj) - Get the hash of an object
120 MIT © [Sindre Sorhus](http://sindresorhus.com)