码迷,mamicode.com
首页 > Windows程序 > 详细

C# X509Certificate类 调用证书

时间:2015-07-30 12:46:08      阅读:812      评论:0      收藏:0      [点我收藏+]

标签:

一、命名空间

using System.Security.Cryptography.X509Certificates;

二、调用代码

string certPath = Server.MapPath("/weixinApp/cert/apiclient_cert.p12");  //证书已上传到对应目录
                    string password = "1244531402";  //证书密码
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                    X509Certificate cert = new X509Certificate(certPath, password);
/// <summary>
        /// CheckValidationResult的定义
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="certificate"></param>
        /// <param name="chain"></param>
        /// <param name="errors"></param>
        /// <returns></returns>
        private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            if (errors == SslPolicyErrors.None)
                return true;
            return false;
        }

 

C# X509Certificate类 调用证书

标签:

原文地址:http://www.cnblogs.com/cookiebin/p/4688608.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!