digitalbazaar / forge

A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
https://digitalbazaar.com/
Other
5.01k stars 767 forks source link

How to generate pkcs12 from pem ? #894

Open jchapelle opened 2 years ago

jchapelle commented 2 years ago

I'm trying to generate a pkcs12 in order to sign pdf files. I have a X509 certificate (certificateString) but can't get a pkcs12 from there.

Could you help ?

    const cert = forge.pki.certificateFromPem(certificateString);
    const asn1Cert = forge.pki.certificateToAsn1(cert);

    // The following line produces an error -> Cannot read PKCS#12 PFX. ASN.1 object is not an PKCS#12 PFX.
    const p12 = forge.pkcs12.pkcs12FromAsn1(asn1Cert);
ikreb7 commented 2 years ago

You could try:

 const p12 = forge.pkcs12.pkcs12FromAsn1(p12Asn1, false);