我正在开展一个项目,我需要能够将预期的SSL证书序列号与我从服务器检索的证书的实际序列号进行比较。我怎么能在C#或VB中做到这一点?
答案 0 :(得分:0)
您应该使用x509certificate2 class:
using System.Net;
using System.Security.Cryptography.X509Certificates;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("Url of the site");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();
var cerificateFromClient = request.ServicePoint.Certificate;
X509Certificate2 certificateFromServer = new X509Certificate2("path to certificate", "Passwod");
var serialFromClient = cerificateFromClient.GetSerialNumberString();
var serialFromServer = certificateFromServer.GetSerialNumberString();
//Checking if both the serial numbers are same
bool isSame = string.Equals(serialFromClient, serialFromClient);
答案 1 :(得分:0)