node-jose icon indicating copy to clipboard operation
node-jose copied to clipboard

Error during decrypting

Open Vishal8523 opened this issue 4 years ago • 5 comments

Occasionally while using the JWE.decrypt function call, I get the following error:

{ message: 'no key found',
  stack: 'Error: no key found\n    at processKey (/home/ubuntu/node_modules/node-jose/lib/jwe/decrypt.js:176:22)\n    at <anonymous>' }

This error appears even though the private key exists in the right location.

Sample code shown:

let importkeystore = jose.JWK.createKeyStore();
importkeystore.add(privatePemData, 'pem').then(function (result) {
           jose.JWE.createDecrypt(result).decrypt(JSON.parse(encryptedData)).
                                   then(function (decryptedData) {
......
});

Appreciate the help in this regards.

Vishal8523 avatar Mar 23 '21 14:03 Vishal8523

Upon analysis, below could be the root cause for the decrypt error:

(node:731) UnhandledPromiseRejectionWarning: Error: Invalid RSAES-OAEP padding.
    at Object.pkcs1.decode_rsa_oaep (/home/root/node_modules/node-forge/lib/pkcs1.js:255:11)
    at Object.decode (/home/root/node_modules/node-forge/lib/rsa.js:1190:30)
    at Object.key.decrypt (/home/root/node_modules/node-forge/lib/rsa.js:1200:19)
    at fallback (/home/root/node_modules/node-jose/lib/algorithms/rsaes.js:137:21)
    at Object.exports.decrypt (/home/root/node_modules/node-jose/lib/algorithms/index.js:109:10)
    at JWKBaseKeyObject.value (/home/root/node_modules/node-jose/lib/jwk/basekey.js:696:25)
    at /home/root/node_modules/node-jose/lib/jwe/decrypt.js:191:31
    at <anonymous>
(node:731) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

Added the kid as part of the key while adding to the keystore as well.

The above promise rejection warning is being thrown on this line in decrypt.js - return algKey.unwrap(rcpt.header.alg, prekey, rcpt.header);

@linuxwolf / @panva : Appreciate your help in this regard.

Vishal8523 avatar Apr 08 '21 10:04 Vishal8523

@Vishal8523 did you found the solution to this?

yashgehi avatar Oct 21 '21 08:10 yashgehi

@linuxwolf @panva can you please help I'm also facing similar issue?

yashgehi avatar Oct 21 '21 08:10 yashgehi

no. Issue still exists. just use jose CLI

Vishal8523 avatar Aug 07 '23 09:08 Vishal8523

server run is right local run is fail

irabbit666666 avatar Sep 12 '24 17:09 irabbit666666