1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-01-31 14:28:04 +00:00

Compare commits

..

No commits in common. "428880002cdba9f64d8397bea466a438802e932a" and "204673694b200f2dd33e87ef64a9a3da5e89eaa0" have entirely different histories.

3 changed files with 0 additions and 60 deletions

View file

@ -1,5 +0,0 @@
{
"imports": {
"jose": "npm:jose@^5.9.6"
}
}

17
jose/deno.lock generated
View file

@ -1,17 +0,0 @@
{
"version": "4",
"specifiers": {
"npm:jose@*": "5.9.6",
"npm:jose@^5.9.6": "5.9.6"
},
"npm": {
"jose@5.9.6": {
"integrity": "sha512-AMlnetc9+CV9asI19zHmrgS/WYsWUwCn2R7RzlbJWD7F9eWYUTGyBmU9o6PxngtLGOiDGPRu+Uc4fhKzbpteZQ=="
}
},
"workspace": {
"dependencies": [
"npm:jose@^5.9.6"
]
}
}

View file

@ -1,38 +0,0 @@
import {
exportJWK,
flattenedDecrypt,
FlattenedEncrypt,
generateKeyPair,
importJWK,
} from "npm:jose";
/*
* JWE_SECRET=$(openssl rand -base64 32) deno run -A jwe.ts
*/
const encryptionKey = await importJWK({
kty: "oct",
k: Deno.env.get("JWE_SECRET"),
});
const keyToEncrypt = await generateKeyPair("ES256", { extractable: true });
const privateKeyJWK = await exportJWK(keyToEncrypt.privateKey);
// encrypt
const jwe = await new FlattenedEncrypt(
new TextEncoder().encode(JSON.stringify(privateKeyJWK)),
)
.setProtectedHeader({
alg: "dir",
enc: "A256GCM",
})
.encrypt(encryptionKey);
// decrypt
const res = await flattenedDecrypt(jwe, encryptionKey);
const jwk = JSON.parse(new TextDecoder().decode(res.plaintext));
console.log({
jwe,
jwk,
});