async function generateKeyAsBase64() { const key = await crypto.subtle.generateKey( { name: "HMAC", hash: "SHA-512" }, true, ["sign", "verify"], ); const keyBuffer = await crypto.subtle.exportKey("raw", key); return btoa(String.fromCharCode(...new Uint8Array(keyBuffer)));}
async function getKeyFromBase64(base64Key: string) { const key = Uint8Array.from(atob(base64Key), (c) => c.charCodeAt(0)); return await crypto.subtle.importKey( "raw", key, { name: "HMAC", hash: "SHA-512" }, true, ["sign", "verify"], );}