简体   繁体   English

如何在 Golang 中给定私钥和证书生成 PKCSs#12 文件?

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

I have a base64 encoded private key and public certificate.我有一个 base64 编码的私钥和公共证书。 My requirement is to create a keystore from it.我的要求是从中创建一个密钥库。 From my analysis, there is no such API in Golang to create it.根据我的分析,Golang 中没有这样的 API 来创建它。 The other way is to generate a PKCSs#12 format file which is a keystore.另一种方法是生成一个 PKCSs#12 格式的文件,它是一个密钥库。

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.crypto/pkcs12提供了一些读取 PKCS#12 文件的基本功能(它是从Azure/go-pkcs12导入的,但目前没有办法编写它们。

Therecommended solution , for now, is use OpenSSL.目前推荐的解决方案是使用 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.还有go-pkcs12但不清楚你应该如何处理结果[]byte (写它们,我猜?),特别是因为你不能提供别名。 So I guess that as Simone says, we should stick to openssl pkcs12 .所以我想正如 Simone 所说,我们应该坚持使用openssl pkcs12

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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