我想通过 golang 生成一些证书,但遇到了一个问题。
当我在 php 中这样做时,它可能像那些代码:
$privkey = openssl_pkey_new([
'digest_alg' => 'des3',
'private_key_bits' => 1024,
'private_key_type' => OPENSSL_KEYTYPE_RSA
]);
$csr = openssl_csr_new([
"countryName" => "EN",
"stateOrProvinceName" => "province",
"localityName" => "city",
"organizationName" => "org",
"organizationalUnitName" => "org",
"commonName" => "name",
], $privkey, ['digest_alg' => 'des3']);
$x509 = openssl_csr_sign($csr, null, $privkey, $days=3650, ['digest_alg' => 'des3']);
openssl_x509_export_to_file($x509, "/path/to/pub.cer");
openssl_pkcs12_export_to_file($x509, "/path/to/pri.pfx", $privkey, "password");
现在使用 golang 我只能创建私钥,但不知道下一步该做什么。请帮助我,非常感谢。
func main() {
keyBytes, err := rsa.GenerateKey(rand.Reader, bitSize)
if err != nil {
panic(err)
}
if err := keyBytes.Validate(); err != nil {
panic(err)
}
dn := pkix.Name{
Country: []string{"EN"},
Organization: []string{"org"},
OrganizationalUnit: []string{"org"},
Locality: []string{"city"},
Province: []string{"province"},
CommonName: "name",
}
asn1Dn, err := asn1.Marshal(dn)
if err != nil {
panic(err)
}
template := x509.CertificateRequest{
Raw: asn1Dn,
SignatureAlgorithm: x509.SHA256WithRSA,
}
csrBytes, err := x509.CreateCertificateRequest(rand.Reader, &template, keyBytes)
// how to do with csrBytes next?
}
江户川乱折腾
相关分类