GithubHelp home page GithubHelp logo

arden / hasha Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sindresorhus/hasha

0.0 2.0 0.0 116 KB

Hashing made simple. Get the hash of a buffer/string/stream/file.

License: MIT License

JavaScript 100.00%

hasha's Introduction




hasha




Hashing made simple. Get the hash of a buffer/string/stream/file.

Build Status

Convenience wrapper around the core crypto Hash class with simpler API and better defaults.

Install

$ npm install --save hasha

Usage

var hasha = require('hasha');

hasha('unicorn');
//=> 'e233b19aabc7d5e53826fb734d1222f1f0444c3a3fc67ff4af370a66e7cadd2cb24009f1bc86f0bed12ca5fcb226145ad10fc5f650f6ef0959f8aadc5a594b27'
var hasha = require('hasha');

// hash the proccess input and output the hash sum
process.stdin.pipe(hasha.stream()).pipe(process.stdout);
var hasha = require('hasha');

// get the MD5 hash of an image
hasha.fromFile('unicorn.png', {algorithm: 'md5'}, function (err, hash) {
	console.log(hash);
	//=> '1abcb33beeb811dca15f0ac3e47b88d9'
});

API

See the Node.js crypto docs for more about hashing.

hasha(input, [options])

input

Required
Type: buffer, string

Buffer you want to hash.

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.

hasha.stream([options])

Returns a hash transform stream.

hasha.fromStream(input, [options], callback)

input

Required
Type: stream

callback(error, hash)

hasha.fromFile(input, [options], callback)

input

Required
Type: string

Path to the file to hash.

callback(error, hash)

hasha.fromFileSync(input, [options])

Returns the hash.

input

Required
Type: string

Path to the file to hash.

Options

encoding

Type: string
Default: hex
Values: hex, base64, buffer, binary

Encoding of the returned hash.

algorithm

Type: string
Default: sha512
Values: md5, sha1, sha256, sha512, etc (platform dependent)

The md5 algorithm is good for file revving, but you should never use md5 or sha1 for anything sensitive. They're insecure.

CLI

$ npm install --global hasha
$ hasha --help

  Usage
    $ hasha <text>
    $ cat <file> | hasha

  Example
    $ hasha unicorn --algorithm=md5
    1abcb33beeb811dca15f0ac3e47b88d9

  Options
    --algorithm  Cipher algorithm: md5,sha1,sha256,sha512   Default: sha512s
    --encoding   Output encoding: hex,base64,buffer,binary  Default: hex

Resources

License

MIT © Sindre Sorhus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.