滚出大麻
当吊销身份证时 你可能不希望它保持不变 永远 所以这个库通过滚动解决了这个问题.
滚动在固定的日期间隔进行,然后给你新的ID来使用!
这个滚动散列库应该能够与各种加密库合作,并且仍然给出有效的滚动ID.
使用量
安装
npm install @bonniernews/rolling-hash
所需资源
节点.js20或更新.
运行
任何密码库都简单易用.
简单地输入给定的散列函数, 到 Base64 函数和 HexFunction 并取回一个滚动的 Hash .
带有自动加密库的示例 :
import rollingHash from "@bonniernews/rolling-hash";
import crypto from "node:crypto";
async function hashFunction(str) {
const arrayBuffer = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(str));
return Array.from(new Uint8Array(arrayBuffer));
}
function toBase64Function(hash) {
return Buffer.from(hash).toString("base64");
}
function toHexFunction(hash) {
return hash.map((b) => b.toString(16).padStart(2, "0")).join("");
}
const rolledHash = await rollingHash("foobar", { hashFunction, toBase64Function, toHexFunction });
// use rolledHash as you want
使用同步加密库的例子 :
import rollingHash from "@bonniernews/rolling-hash";
import cryptoJs from "crypto-js";
function hashFunction(str) {
return cryptoJs.SHA256(str);
}
function toBase64Function(hash) {
return hash.toString(cryptoJs.enc.Base64);
}
function toHexFunction(hash) {
return hash.toString(cryptoJs.enc.Hex);
}
const rolledHash = rollingHash("foobar", { hashFunction, toBase64Function, toHexFunction });
// use rolledHash as you want
如果使用普通JS:
const { default: rollingHash } = require("@bonniernews/rolling-hash");
免责声明
散列的滚动时间可能改变.
我们使用 Date 类来处理散列, 如果修改了它的话, 我们无法保证这将100%的时间工作 .