I have a p12 certificate which I need to use to create digital signatures to be sent in the headers of a HTTP request. I'm using the node-forge package to get the privateKey and certificate bags from the p12.
const p12Asn1 = forge.asn1.fromDer(keyFile)
const p12 = forge.pkcs12.pkcs12FromAsn1(p12Asn1, passwordHash)
const certificateBags = p12.getBags({ bagType: forge.pki.oids.certBag })
const certificate = certificateBags[forge.pki.oids.certBag][0].cert
I have instructions from the API vendor on creating the digital signature. One step is:
keyId - Get X509 certificate that accompanies the private key as a byte array and Base64 encode. This field is required.
How can I Base64 encode the certificate extracted from the bags above? I have tried various forge utility methods, forge.util
, but the certificate is an object at this point so I'm not sure what bit needs encoding.