我正在嘗試讓客戶端證書身份驗證正常工作,在閱讀https://developer.mozilla.org/en-US/docs/Web/HTML/Element/keygen 后,我意識到我需要解析一些 asn1。我試圖使用的結構是這樣的:type PublicKeyAndChallenge struct { Spki asn1.BitString Challenge asn1.BitString}type SignedPublicKeyAndChallenge struct{ PublicKeyAndChallenge PublicKeyAndChallenge SignitureAlgorithm asn1.BitString Signiture asn1.BitString}我將 base64 編碼的 asn1 解碼為 []byte,然后嘗試將 asn1 解組到結構中。signeeKeySigned := make([]byte, 2048) _ , err = base64.StdEncoding.Decode(signeeKeySigned, signeePubKeySigned) if ( err != nil ){ log.Fatal(err) } //Parse should be asn.1 encoded var signee SignedPublicKeyAndChallenge _, err = asn1.Unmarshal(signeeKeySigned, &signee) if err != nil { log.Fatal(err) } 我收到一個結構錯誤,所以我相信我在 go 中的結構一定不正確,但我無法弄清楚。
1 回答

大話西游666
TA貢獻1817條經驗 獲得超14個贊
我做了一些鴨鴨,找到了提供 asn.1 類定義的 rfc320 并讓它工作了!
現在的結構是:
type SubjectPublicKeyInfo struct {
Algorithm pkix.AlgorithmIdentifier
SubjectPublicKey asn1.BitString
}
type PublicKeyAndChallenge struct {
Spki SubjectPublicKeyInfo
Challenge string
}
type SignedPublicKeyAndChallenge struct{
PublicKeyAndChallenge PublicKeyAndChallenge
SignitureAlgorithm pkix.AlgorithmIdentifier
Signiture asn1.BitString
}
- 1 回答
- 0 關注
- 160 瀏覽
添加回答
舉報
0/150
提交
取消