Giter VIP home page Giter VIP logo

js-sha1's Introduction

js-sha1

Build Status Coverage Status
NPM
A simple SHA1 hash function for JavaScript supports UTF-8 encoding.

Demo

SHA1 Online SHA1 File Checksum Online

Download

Compress
Uncompress

Installation

You can also install js-sha1 by using Bower.

bower install js-sha1

For node.js, you can use this command to install:

npm install js-sha1

Notice

NIST formally deprecated use of SHA-1 in 2011 and disallowed its use for digital signatures in 2013, and declared that it should be phased out by 2030. However, SHA-1 is still secure for HMAC. wiki

Usage

You could use like this:

sha1('Message to hash');
var hash = sha1.create();
hash.update('Message to hash');
hash.hex();

// HMAC
sha1.hmac('key', 'Message to hash');

var hash = sha1.hmac.create('key');
hash.update('Message to hash');
hash.hex();

Node.js

If you use node.js, you should require the module first:

var sha1 = require('js-sha1');

TypeScript

If you use TypeScript, you can import like this:

import { sha1 } from 'js-sha1';

RequireJS

It supports AMD:

require(['your/path/sha1.js'], function(sha1) {
// ...
});

Example

sha1(''); // da39a3ee5e6b4b0d3255bfef95601890afd80709
sha1('The quick brown fox jumps over the lazy dog'); // 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
sha1('The quick brown fox jumps over the lazy dog.'); // 408d94384216f890ff7a0c3528e8bed1e0b01621

// It also supports UTF-8 encoding
sha1('中文'); // 7be2d2d20c106eee0836c9bc2b939890a78e8fb3

// It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
sha1([]); // da39a3ee5e6b4b0d3255bfef95601890afd80709
sha1(new Uint8Array([])); // da39a3ee5e6b4b0d3255bfef95601890afd80709

// Different output
sha1(''); // da39a3ee5e6b4b0d3255bfef95601890afd80709
sha1.hex(''); // da39a3ee5e6b4b0d3255bfef95601890afd80709
sha1.array(''); // [218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9]
sha1.digest(''); // [218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9]
sha1.arrayBuffer(''); // ArrayBuffer

// HMAC
sha1.hmac.hex('key', 'Message to hash');
sha1.hmac.array('key', 'Message to hash');
// ...

License

The project is released under the MIT license.

Contact

The project's website is located at https://github.com/emn178/js-sha1
Author: Chen, Yi-Cyuan ([email protected])

js-sha1's People

Contributors

dependabot[bot] avatar emn178 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-sha1's Issues

How are Arrays supported?

Question:
If I have array like ["hello","Bye"] and pass it to the sha1() function what will happen?

It is coming out that passing ["hello","Bye"] and ["hello","Hi"] produces same hash???

Thanks
harsh

Warn users about the insecurity of SHA-1

I believe that a warning should be in place on this project for any given user that SHA-1 should not be used unless there is a very good reason for it. I know that the majority of people who manage to make it to this library will be here for good reason and not using this for security in production, but it is vital that we still have information, even in the basic form of a README header.

Usage of eval()

Version 0.6.0 uses eval() at columns 1036 and 1064 (minified version), which is not quite good for browser extension development.

Is it possible to avoid usage of eval()?

Previously used version 0.4.1 which did not have any eval() statements.

Words with accents

You don't get the expected result with words with accents, for example, with the word "aécio" you expect ¨9e4e5d978deced901d621475b03f1ded19e945bf¨ and you get ¨3aebdee65023cb421e5150f09ff096bf71ec3686¨.

var sha1 = require('js-sha1');

console.log('# # # # # js-sha1 lib # # # # #');
console.log( sha1( 'aécio' ) );
--> 3aebdee65023cb421e5150f09ff096bf71ec3686


var sha1 = require('sha1');

console.log('# # # # # sha1 lib # # # # #');
console.log( sha1( 'aécio' ) );
--> 9e4e5d978deced901d621475b03f1ded19e945bf

benchmark

Could you do some benchmark on a few sha1(uint8array) client implementations? would be interesting to see

  • js-sha1
  • sha1
  • Web crypto sha1 = crypto.subtle.digest.bind(crypto.subtle, { name: 'sha-1' })
  • Rusha

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.