Missing Private Key after updating Node

48 views Asked by At

I'm having an issue maintaining a legacy system where I have to upgrade from Node 10 to Node 20, although I've isolated the problem to after upgrading to node 12.

The issue is with the crypto privateDecrypt method, which worked fine when in node 10, but in node 12 gives the error:

error:040650B3:rsa routines:rsa_ossl_private_decrypt:missing private key

and then by node 20 gives the slightly different error:

error:020000B3:rsa routines::missing private key

Here is the code needed to repro the issue:

    message = fs.readFileSync(`input`)
  
    const decrpyted = crypto.privateDecrypt({
      key: fs.readFileSync(`stats.pem`),
      padding: crypto.constants.RSA_PKCS1_PADDING
    }, message);

    
    res.send(decrpyted);

(It doesn't really matter what the message is because the missing key error appears before it tries to decrypt it, so if I get far enough that it fails on the decryption its still progress!)

Unfortunately I suspect it may be an issue with the key I'm using, but I cant provide that (because, you know, it's private) - and I also cannot create a new key pair, because too many systems have the old public key embedded that we can't change.

Any suggestion on where to go next would be appreciated!


Edits:

The .pem file looks like:

-----BEGIN PRIVATE KEY-----
...
...
...
-----END PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
...
...
...
-----END CERTIFICATE-----
0

There are 0 answers