1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-01-30 22:08:02 +00:00

use FlattenedJWE

This commit is contained in:
Nebel 2024-12-03 13:40:25 +09:00
parent 3d8c2deba7
commit 428880002c
Signed by: nebel
GPG key ID: 79807D08C6EF6460

View file

@ -1,7 +1,7 @@
import {
compactDecrypt,
CompactEncrypt,
exportJWK,
flattenedDecrypt,
FlattenedEncrypt,
generateKeyPair,
importJWK,
} from "npm:jose";
@ -19,7 +19,7 @@ const keyToEncrypt = await generateKeyPair("ES256", { extractable: true });
const privateKeyJWK = await exportJWK(keyToEncrypt.privateKey);
// encrypt
const jwe = await new CompactEncrypt(
const jwe = await new FlattenedEncrypt(
new TextEncoder().encode(JSON.stringify(privateKeyJWK)),
)
.setProtectedHeader({
@ -29,7 +29,7 @@ const jwe = await new CompactEncrypt(
.encrypt(encryptionKey);
// decrypt
const res = await compactDecrypt(jwe, encryptionKey);
const res = await flattenedDecrypt(jwe, encryptionKey);
const jwk = JSON.parse(new TextDecoder().decode(res.plaintext));
console.log({