This commit is contained in:
lloydzhou
2024-08-01 18:58:07 +08:00
parent e1d6131f13
commit c359b92ddc
4 changed files with 7 additions and 19 deletions

View File

@@ -1,17 +1,14 @@
"use server";
import * as crypto from "node:crypto";
import { createHash, createHmac } from "node:crypto";
// 使用 SHA-256 和 secret 进行 HMAC 加密
function sha256(message: any, secret = "", encoding?: string) {
return crypto
.createHmac("sha256", secret)
return createHmac("sha256", secret)
.update(message)
.digest(encoding as any);
}
// 使用 SHA-256 进行哈希
function getHash(message: any, encoding = "hex") {
return crypto
.createHash("sha256")
return createHash("sha256")
.update(message)
.digest(encoding as any);
}