Files
cwd/cwd-api/src/utils/crypto.ts
2026-01-21 10:53:11 +08:00

9 lines
303 B
TypeScript

export async function hashKey(key: string): Promise<string> {
const encoder = new TextEncoder();
const data = encoder.encode(key);
const hash = await crypto.subtle.digest('SHA-256', data);
return Array.from(new Uint8Array(hash))
.map((b) => b.toString(16).padStart(2, '0'))
.join('');
}