Convert WebCrypto algorithm to JOSE alg #172
-
Suppose I get a CryptoKey that looks something like this: const randomKey = {
"type": "secret",
"extractable": false,
"algorithm": { "name": "AES-KW", "length": 256 },
"usages": ["wrapKey", "unwrapKey"]
}; Now if I want to create a JWE with it: const jwe = await new CompactEncrypt(encoder.encode('secret message'))
.setProtectedHeader({ alg: "A256KW", enc: 'A256GCM' }) //bad to assume the algorithm will always be A256KW
.encrypt(randomKey) Since, I cannot extract the key to JWK, I don't see an great way to convert "algorithm" per WebCrypto to >>> "alg" per JOSE. ex: What I'd like to do is have a const jwe = await new CompactEncrypt(encoder.encode('secret message'))
.setProtectedHeader({ alg: getAlgFromKey(randomKey), enc: 'A256GCM' }) //always works!
.encrypt(thirdPartyKey) I think I pretty much want the opposite of this: jose/src/runtime/browser/jwk_to_key.ts Lines 7 to 106 in 5487311 Does panva/JOSE have this somewhere that I missed? Would it be helpful for me to create it and submit a PR? note: here are the explicit mappings. I believe this is the algorithm to alg mapping function in Chrome/blink. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
How would such API deal
How would such API work when node's KeyObject is passed in? It looks like a WebCrypto only API. |
Beta Was this translation helpful? Give feedback.
Hi @jonathanstanley
How would such API deal
alg
value?alg
andenc
algorithms but the result algorithm identifier not being the same?How would such API work when node's KeyObject is passed in? It looks like a WebCrypto only API.