forge icon indicating copy to clipboard operation
forge copied to clipboard

When trying to use certificateFromPem i got failure : "Cannot read public key. OID is not RSA.

Open olfa-arfani opened this issue 5 years ago • 5 comments

After importing my PEM encoded X.509 certificate, and trying to do const cert = forge.pki.certificateFromPem(myCertificate) I got this error Cannot read public key. OID is not RSA By trying to use another certificate it worked.. Would you please provide help to overcome this issue?

olfa-arfani avatar Aug 09 '19 07:08 olfa-arfani

Hi, have same error 'Cannot read public key. OID is not RSA.' on add certificate

const p7 = forge.pkcs7.createSignedData();
p7.addCertificate(fs.readFileSync('cert.pem', {encoding: 'utf8'}));

cert.pem file is:

-----BEGIN CERTIFICATE-----
MIIBJTCBy6ADAgECAgRdtyAQMAoGCCqGSM49BAMCMBUxEzARBgNVBAMMCmNhLXNz
dmRlbW8wIBcNMTkxMDI4MTcwNjI0WhgPMjA2OTEwMjcxNzA2MjRaMA8xDTALBgNV
BAMMBHVzZXIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATk96n0BUDkEJK/iiWO
EjWFatMrlEYJmMh2kvFouQjIh5ozEfKZUcLEBEvODEA8ZFuxicOYrOSKvdl9G3Ut
d6v3ow0wCzAJBgNVHRMEAjAAMAoGCCqGSM49BAMCA0kAMEYCIQCCkDBL9+2juC7R
q56VlgiJ3qMqywkEj/Ppzll7uS2UbAIhALQ3BrHJOXVflo5KnOFVmr4P0OZEptTV
X0tUke1biXyg
-----END CERTIFICATE-----

what is wrong?

eddso avatar May 14 '20 12:05 eddso

Any update for this issue? We had the sam problem when calling certificateFromPem to decode the cert.

binli0114 avatar Jun 30 '20 22:06 binli0114

I ran into same problem. I suspect it's because the certificate is for elliptic curve key, not an RSA key. Can anyone confirm this?

leg0 avatar Dec 28 '20 22:12 leg0

Seems to be related to elliptical curve support https://github.com/digitalbazaar/forge/issues/116.

Desnoo avatar May 25 '21 15:05 Desnoo

@olfa-arfani @eddso @binli0114 Any updates on this ticket? Have you folks resolved this using some other method?

I had to use jsrasign and this workaround helped me validate the certificate chain. However now I am left with 2 dependencies in my project and node-forge API is far more elegant than the jsrasign's

yogeshwar-chaudhari-20 avatar Jun 20 '22 05:06 yogeshwar-chaudhari-20