https://github.com/duzun/sync-sha1
Tiny sha1 in JavaScript
https://github.com/duzun/sync-sha1
Last synced: 6 months ago
JSON representation
Tiny sha1 in JavaScript
- Host: GitHub
- URL: https://github.com/duzun/sync-sha1
- Owner: duzun
- License: mit
- Created: 2020-03-14T22:02:03.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-23T07:28:17.000Z (over 5 years ago)
- Last Synced: 2025-03-30T11:34:31.423Z (7 months ago)
- Language: JavaScript
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sync-sha1 [](https://travis-ci.org/duzun/sync-sha1)
Synchronous sha1 in JavaScript
Shamelessly stolen from [jbt/tiny-hashes](https://github.com/jbt/tiny-hashes) and improved.
It is basically a synchronous `sha1()` hash function for browsers, with no guaranties.
The improvement consists in the usage of the `Uint32Array` instead of `Array` internaly
and compatibility with `Uint8Array` on input/output.For Node.js you should use the [`crypto`](https://nodejs.org/api/crypto.html#crypto_crypto) module!
## Usage
### The Easy way
```js
var sha1 = require('sync-sha1');sha1('sync-sha1').toString('hex'); // "150f7d2a6e9f80f03c639b17878bce65b5a033a8"
```### The Tiny way
```js
import sha1 from 'sync-sha1/rawSha1'; // rollup.js ?const buffer = new Uint8Array('sync-sha1'.split('').map((c) => c.charCodeAt(0)));
const hash = sha1(buffer);
hash.reduce((r, c) => r += (c >>> 0).toString(16).padStart(2,'0'), ''); // "150f7d2a6e9f80f03c639b17878bce65b5a033a8"
```### The Native Browser way
```js
import sha1 from 'sync-sha1/asyncSha1'; // rollup.js ?const hash = await sha1('sync-sha1');
hash.toString('hex'); // "150f7d2a6e9f80f03c639b17878bce65b5a033a8"
```Direct Browser include:
```html
```
Use it at your own risk!