简体   繁体   中英

How to generate a PKCSs#12 file given private key and certificate in Golang?

I have a base64 encoded private key and public certificate. My requirement is to create a keystore from it. From my analysis, there is no such API in Golang to create it. The other way is to generate a PKCSs#12 format file which is a keystore.

Please let me know the solution if any.

The package crypto/pkcs12 provides some basic functions for reading PKCS#12 files (it was imported from Azure/go-pkcs12 , but there is currently no way to write them.

Therecommended solution , for now, is use OpenSSL.

$ openssl pkcs12 -export -inkey private.key -in certificate.pem -certfile intermediates.crt -out certificate.pfx

There's also go-pkcs12 but it's not clear what should you do with the resulting []byte (write them, I guess?), specially since you can't provide the alias. So I guess that as Simone says, we should stick to openssl pkcs12 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM