BLAKE2s implementation in JavaScript
====================================
BLAKE2 is a fast and secure cryptographic hash function.
This is a pure JavaScript public domain implementation of its BLAKE2s flavor
(currently without tree mode support).
* [BLAKE2s-js Demo](https://dchest.github.io/blake2s-js/)
* [BLAKE2 Website](https://blake2.net)
[![Build Status](https://travis-ci.org/dchest/blake2s-js.svg?branch=master)
](https://travis-ci.org/dchest/blake2s-js)
**This implementation is maintained, but will not receive new features. If you're looking for a full implementation of BLAKE2s, BLAKE2Xs and BLAKE2b, see my packages from [StableLib](https://github.com/StableLib/stablelib): `@stablelib/blake2s`, `@stablelib/blake2xs`, and `@stablelib/blake2b`.**
Installation
------------
Via NPM:
$ npm install blake2s-js
or just download `blake2s.min.js`.
Usage
-----
### new BLAKE2s(digestLength, key)
### new BLAKE2s(digestLength, config)
Creates a new instance of BLAKE2s hash with the given length of digest (default
and maximum 32) and an optional secret key (a `Uint8Array` or `Array` of
bytes) or config object in the following format:
{
salt: // 8-byte Uint8Array or Array of bytes
personalization: // 8-byte Uint8Array or Array of bytes
key: // 0-32-byte Uint8Array or Array of bytes
}
All keys in config are optional.
#### .update(data[, offset, length])
Updates the hash with data (a `Uint8Array` or `Array` of bytes). starting at
the given `offset` (optional, defaults to 0) and consuming the given `length`
(optional, defaults to the length of `data` minus `offset`).
Returns this instance to enable method chaining.
#### .digest()
Returns a `Uint8Array` with the digest of consumed data. Further updates will
throw error. Repeat calls of `digest()` will return the same digest.
#### .hexDigest()
Like `digest()`, but returns a hex-encoded string.
#### BLAKE2s.digestLength = 32
Maximum digest length.
#### BLAKE2s.blockLength = 64
Block size of the hash function.
#### BLAKE2s.keyLength = 32
Maximum key length.
#### BLAKE2s.personalizationLength = 8
Length of personalization parameter.
#### BLAKE2s.saltLength = 8
Length of salt parameter.
Example
-------
```javascript
var h = new BLAKE2s(32);
h.update(new Uint8Array([1,2,3]));
h.hexDigest(); // returns string with hex digest
h.digest(); // returns Uint8Array
// Keyed:
var key = new Uint8Array(BLAKE2s.keyLength);
window.crypto.getRandomValues(key);
var h = new BLAKE2s(32, key);
...
// Keyed and salted:
var key = new Uint8Array(BLAKE2s.keyLength);
var salt = new Uint8Array(BLAKE2s.saltLength);
window.crypto.getRandomValues(key);
window.crypto.getRandomValues(salt);
var h = new BLAKE2s(32, { key: key, salt: salt });
...
// Personalized:
var data = new Uint8Array([1, 2, 3]);
var pers1 = new Uint8Array([1, 0, 0, 0, 0, 0, 0, 0]);
var h1 = new BLAKE2s(32, { personalization: pers1 });
h1.update(data);
var pers2 = new Uint8Array([2, 0, 0, 0, 0, 0, 0, 0]);
var h2 = new BLAKE2s(32, { personalization: pers2 });
h2.update(data);
h1.hexDigest() !== h2.hexDigest() // true
```
没有合适的资源?快使用搜索试试~ 我知道了~
JavaScript中的BLAKE2s加密哈希函数.zip
共13个文件
js:3个
json:3个
html:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 175 浏览量
2023-03-26
23:56:21
上传
评论
收藏 35KB ZIP 举报
温馨提示
JavaScript中的BLAKE2s加密哈希函数.zip
资源推荐
资源详情
资源评论
收起资源包目录
JavaScript中的BLAKE2s加密哈希函数.zip (13个子文件)
blake2s-js-master
.travis.yml 69B
LICENSE 1KB
demo
index.html 2KB
blake2s.min.js 13KB
package.json 744B
package-lock.json 1016B
blake2s.d.ts 841B
test
test.html 215B
test.js 41KB
blake2s.js 35KB
.gitignore 30B
tsconfig.json 109B
README.md 3KB
共 13 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功