JWEDecryptionFailed error when using docker #383
Unanswered
federico-moretti
asked this question in
Q&A
Replies: 2 comments 5 replies
-
Don't know how I could be of help. Most likely your keys are just not set correctly. |
Beta Was this translation helpful? Give feedback.
5 replies
-
Thanks @panva for the support, at the end I got this working using this steps: # create jwt keys
openssl ecparam -name prime256v1 -genkey -noout -out private-ec.pem
openssl ec -in private-ec.pem -pubout -out public-ec.pem
openssl pkcs8 -topk8 -nocrypt -in private-ec.pem -out private-ec-pcks8.pem
# create jwe keys
openssl pkey -in private-okp.pem -pubout -out public-okp.pem
openssl genpkey -algorithm x25519 -out private-okp.pem Encrypt: const signKey = await importPKCS8(params.signKey, 'ES256');
const encryptKey = await importSPKI(params.encryptKey, 'ECDH-ES');
const jwt = await new SignJWT(params.body)
.setProtectedHeader({ alg: 'ES256' })
.setExpirationTime(params.expirationTime)
.sign(signKey);
const plaintext = Buffer.from(jwt);
return await new CompactEncrypt(plaintext)
.setProtectedHeader({ alg: 'ECDH-ES', enc: 'A128CBC-HS256', kid: 'PRA-OKP' })
.encrypt(encryptKey); Decrypt: const verifyKey = await importSPKI(params.verifyKey, 'ES256');
const decryptKey = await importPKCS8(params.decryptKey, 'ECDH-ES');
const jweDecrypted = await compactDecrypt(params.token, decryptKey, { keyManagementAlgorithms: ['ECDH-ES'] });
const { payload } = await jwtVerify(jweDecrypted.plaintext, verifyKey, { algorithms: ['ES256'] });
return payload as JWTPayload & T; It seems that everything match up correctly and works fine. The only thing that makes me wonder is why changing the Again thank you for the support and patience! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I'm getting this error
JWEDecryptionFailed
when running some tests in the CI with the docker imagenode:16.13-alpine3.14
while I'm having no problem on my machine withnode v16.10.0
.I don't exclude that there is something wrong with my encryption method (which I use only for the tests) but I'm pretty sure the decrypt is correct as I already asked here.
This is the encrypt method I'm using:
The keys for the tests are these:
Thank you for the help!
Beta Was this translation helpful? Give feedback.
All reactions