我想解析X509 sertificate自定義擴展。 (我創建了一個自定義擴展類型爲「證書策略」的自簽名證書)。我需要解析這個「證書策略」及其值。編程方式,我可以得到定製extention是「證書策略」的名字,但我不能說我現在用的就是它的values..The代碼如下所示:如何解析X509 SSL證書自定義擴展「證書策略」?
public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
var cert = (X509Certificate2)certificate;
foreach (X509Extension ext in cert.Extensions)
{
// AsnEncodedData x = new AsnEncodedData(ext.Oid, ext.RawData);
MessageBox.Show("Name: " + ext.Oid.FriendlyName + "\nValue: " + ext.Oid.Value);
}
return true;
}
此代碼onlye顯示「證書政策「但我需要的政策在下面所示的解析元素:在證書策略元素
值:求助
[1]Certificate Policy:
Policy Identifier=1.2.3.4
[2]Certificate Policy:
Policy Identifier=1.5.6.7.8
[3]Certificate Policy:
Policy Identifier=1.3.5.8
[3,1]Policy Qualifier Info:
Policy Qualifier Id=CPS
Qualifier:
Tarzano
[3,2]Policy Qualifier Info:
Policy Qualifier Id=User Notice
Qualifier:
Notice Reference:
Organization=Tarzano Ltd
Notice Number=1, 2, 3, 4
Notice Text=Buraya mesaj yazilabilir
的感謝!
感謝您的回答CryptoGuy。此課程解決了我的問題: http://msdn.microsoft.com/en-us/library/system.security.cryptography.asnencodeddata(v=vs.110).aspx – user2084339 2014-10-25 19:05:50