INNER CODE UNIT · TypeScript
createEncrypt
vercel/server-components-notes-demo · libs/session.ts:36
export function createEncrypt() {
return async function (data) {
const pwHash = await crypto.subtle.digest('SHA-256', pwUtf8)
const encryptKey = await crypto.subtle.importKey(
'raw',
pwHash,
algo,
false,
['encrypt']
)
const encrypted = await crypto.subtle.encrypt(
algo,
encryptKey,
encode(data)
)
return arrayBufferToBase64(encrypted)
}
}