sf-apple-sdk
Version:
Apple SF SDK for SF WMS
15 lines (14 loc) • 580 B
JavaScript
import { md5 } from "@noble/hashes/legacy";
import base64 from "base64-js";
/** 将 Uint8Array 转为小写 hex 字符串 */
function toHexLowerCase(bytes) {
return Array.from(bytes)
.map((b) => b.toString(16).padStart(2, "0"))
.join(""); // 默认就是小写
}
export function generateSFDigest(json, specialStr) {
const raw = json + specialStr;
const hash = md5(new TextEncoder().encode(raw));
const hex = toHexLowerCase(hash); // ✅ 小写 hex
return base64.fromByteArray(new TextEncoder().encode(hex)); // ✅ 编码 hex 字符串本身
}