Migrating JWE decrypt/verify from 2.0.5 to 4.5.0 #360
Answered
by
federico-moretti
federico-moretti
asked this question in
Q&A
-
Hello! Old script: // the "token" var is a string that I receive as query string
const decryptKey = <JWT.OKPKey>JWT.asKey(privateKey, { alg: 'ECDH-ES', use: 'enc' });
const jws = JWE.decrypt(token, decryptKey, { keyManagementAlgorithms: ['ECDH-ES'] }).toString();
const verifyKey = <JWT.ECKey>JWT.asKey(publicKey, { alg: 'ES256', use: 'sig' });
return JWE.verify(jws, verifyKey, { algorithms: ['ES256', 'HS256', 'EdDSA'] }); Is there anyone that can help me? Thank you. |
Beta Was this translation helpful? Give feedback.
Answered by
federico-moretti
Feb 14, 2022
Replies: 1 comment 2 replies
-
I resolved with the following code: // the "token" var is a string that I receive as query string
const publicKey = await jose.importSPKI(PUBLIC_KEY, 'ES256');
const privateKey = await jose.importPKCS8(PRIVATE_KEY, 'ECDH-ES');
const decrypted = await jose.compactDecrypt(token, privateKey, { keyManagementAlgorithms: ['ECDH-ES'] });
return await jose.jwtVerify(decrypted.plaintext, publicKey, { algorithms: ['ES256'] }); |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
federico-moretti
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I resolved with the following code: