Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何验证我的自签名证书_C#_Security_Cryptography_Certificate - Fatal编程技术网

C# 如何验证我的自签名证书

C# 如何验证我的自签名证书,c#,security,cryptography,certificate,C#,Security,Cryptography,Certificate,我的web服务器正在使用自签名SSL证书。我可以通过自己实施验证检查来连接它: private static Boolean ValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyerrors) { return certificate.GetCertHashString().equals("ABCDEF"); }

我的web服务器正在使用自签名SSL证书。我可以通过自己实施验证检查来连接它:

private static Boolean ValidateCertificate(object sender,
     X509Certificate certificate, X509Chain chain,
     SslPolicyErrors sslpolicyerrors)
{
  return certificate.GetCertHashString().equals("ABCDEF");
}

private void Connect(String requestUrl)
{
    ServicePointManager.ServerCertificateValidationCallback = ValidateCertificate;
    var request = (HttpWebRequest) WebRequest.Create(requestUrl);
    var response = request.GetResponse();
    //...
}
GetCertHashString()
返回的哈希值与硬编码值进行比较,以验证这确实是预期的证书,这样安全吗


“真实”证书是链的一部分,必须验证到自签名的根证书。我猜根证书的可验证部分硬编码到每个应用程序中。这使我相信,只要硬编码的值不被篡改,我的自签名证书将与任何其他证书一样安全,这意味着访问机器本身,在这种情况下,标准根证书也可能被篡改。对吗?

这个问题毫无意义。所有自签名证书都证明您在自言自语。它对公共互联网上的任何东西都没有用。为什么不将您的自签名证书添加到可信证书存储中?@dtb:因为我需要在windows下的.net4和ubuntu和solaris下的mono上支持此应用程序。做一个简单的检查似乎比处理操作系统的所有麻烦要容易得多。@Ramhound:我不理解你的评论。我不想和自己说话,我想让我的客户机和我的服务器说话,并能够验证他是否获得了正确的证书,以便通信是安全的。即使它是来自Verisign的付费证书,我也需要在某个时候验证根证书,它本身是自签名的,问题是:如何将自签名证书放到客户端的机器上,如何确保客户端机器上的证书不被篡改?