2016-09-26 254 views
0

我有一個ASP.net Web應用程序,我的客戶端需要使用客戶端v3證書對我的網站進行身份驗證。客戶端身份驗證 - 處理客戶端證書

所有我需要檢查的是: 1-證書有效期 2-「印發給CN」具有特定值

我做我的MVC行動如下:

var req = Request.ClientCertificate; 

req有一個名爲IsValid的屬性,這對於要求(1)是足夠的。現在,問題在於我無法檢查CN,因爲我認爲它存儲在類型byte[0]的另一個屬性Certificate中。

我想讀這樣的證書:

var x509 = new X509Certificate(req.Certificate); 

,但我得到兩個例外:

'x509.Issuer' threw an exception of type 'System.Security.Cryptography.CryptographicException' 
'x509.Subject' threw an exception of type  'System.Security.Cryptography.CryptographicException' 

我如何讀取證書?

回答