mirror of
https://github.com/kou029w/_.git
synced 2025-01-30 22:08:02 +00:00
use FlattenedJWE
This commit is contained in:
parent
3d8c2deba7
commit
428880002c
1 changed files with 4 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
import {
|
import {
|
||||||
compactDecrypt,
|
|
||||||
CompactEncrypt,
|
|
||||||
exportJWK,
|
exportJWK,
|
||||||
|
flattenedDecrypt,
|
||||||
|
FlattenedEncrypt,
|
||||||
generateKeyPair,
|
generateKeyPair,
|
||||||
importJWK,
|
importJWK,
|
||||||
} from "npm:jose";
|
} from "npm:jose";
|
||||||
|
@ -19,7 +19,7 @@ const keyToEncrypt = await generateKeyPair("ES256", { extractable: true });
|
||||||
const privateKeyJWK = await exportJWK(keyToEncrypt.privateKey);
|
const privateKeyJWK = await exportJWK(keyToEncrypt.privateKey);
|
||||||
|
|
||||||
// encrypt
|
// encrypt
|
||||||
const jwe = await new CompactEncrypt(
|
const jwe = await new FlattenedEncrypt(
|
||||||
new TextEncoder().encode(JSON.stringify(privateKeyJWK)),
|
new TextEncoder().encode(JSON.stringify(privateKeyJWK)),
|
||||||
)
|
)
|
||||||
.setProtectedHeader({
|
.setProtectedHeader({
|
||||||
|
@ -29,7 +29,7 @@ const jwe = await new CompactEncrypt(
|
||||||
.encrypt(encryptionKey);
|
.encrypt(encryptionKey);
|
||||||
|
|
||||||
// decrypt
|
// decrypt
|
||||||
const res = await compactDecrypt(jwe, encryptionKey);
|
const res = await flattenedDecrypt(jwe, encryptionKey);
|
||||||
const jwk = JSON.parse(new TextDecoder().decode(res.plaintext));
|
const jwk = JSON.parse(new TextDecoder().decode(res.plaintext));
|
||||||
|
|
||||||
console.log({
|
console.log({
|
||||||
|
|
Loading…
Add table
Reference in a new issue