我正在使用MDNS,并且需要宣布帶有MDNS記錄的主題KeyId。SKI 是 x509 證書的一部分,但無法從最終的 TLS 證書中讀取:priv, err := rsa.GenerateKey(rand.Reader, 2048)if err != nil { log.Fatal(err)}template := x509.Certificate{ SerialNumber: big.NewInt(1), Subject: pkix.Name{ Organization: []string{"Acme Co"}, }, NotBefore: time.Now(), NotAfter: time.Now().Add(time.Hour * 24 * 180), KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, BasicConstraintsValid: true,}derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, publicKey(priv), priv)if err != nil { log.Fatalf("Failed to create certificate: %s", err)}tlsCert := tls.Certificate{ Certificate: [][]byte{derBytes}, PrivateKey: priv,}如何從結果中提取或生成SKI?tls.Certificate
1 回答

catspeake
TA貢獻1111條經驗 獲得超0個贊
您必須自己構建它并將其作為證書模板提供。SubjectKeyId
RFC 5280 第 4.2.1.2 節建議了幾種生成主題密鑰標識符的潛在方法。最受歡迎的是只獲取公鑰的ASN.1編碼的SHA1哈希。例如,如果 是 ,則可以執行以下操作:pub
*rsa.PublicKey
keyBytes := x509.MarshalPKCS1PublicKey(pub) keyHash := sha1.Sum(keyBytes) ski := keyHash[:]
,然后在調用 之前將證書模板的字段設置為 。SubjectKeyId
ski
x509.CreateCertificate
- 1 回答
- 0 關注
- 165 瀏覽
添加回答
舉報
0/150
提交
取消