簡體   English   中英

如何向證書添加私鑰

[英]How to add private key to certificate

我正在嘗試使用創建csr的Go-in-one實用程序進行創建,發送它,然后(由安全人員批准后)獲得簽名證書,最后創建證書+私有以將其添加到瀏覽器或系統中。

現在,我可以做所有事情直到最終完成:在已簽名的證書中添加私有證書。 使用openssl我可以通過以下方式做到這一點:

openssl pkcs12 -export -out sergo.kurbanov.p12 -in sergo.kurbanov.crt -inkey sergo.kurbanov.key -name "Sergo Kurbanov"

有人可以建議Go中的方法嗎?

PS我正在使用Dogtag證書系統

我發現了這個決定:不幸的是,標准的Go pkcs12庫沒有包含所需的功能,但是有HashiCorp的“ github.com/hashicorp/packer/builder/azure/pkcs12”軟件包的版本,其中包含所需的功能:

// Read our key created by openssl genrsa -out... or by Go 
// rsa.GenerateKey/EncryptPEMBlock...
pemKey,_ := ioutil.ReadFile("private.key")

// Convert pem to rsa key because it required for pkcs12.Encode
var rsaKey *rsa.PrivateKey
rsaKey,_ = dogtag.PemToRSA(pemKey,"our_private_secret")

// Get signed cert from dogtag CMS
var cert *x509.Certificate
cert,_ = dogtag.GetCert("0xF0F05A8")

// Create combined certificate
pfx,_ := pkcs12.Encode(cert.Raw, pemKey, "somesecret")

outFile,_ := os.Create("priv_plus_cert.p12")
defer outFile.Close()
outFile.Write(pfx)

最后,我們獲得了適合添加到鑰匙串或瀏覽器的證書。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM