首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发送数字证书

发送数字证书
EN

Security用户
提问于 2013-04-27 14:54:37
回答 1查看 435关注 0票数 2

我使用makecert工具来创建:

  1. 自签证书
  2. 使用自签名证书的服务器证书。
  3. 使用自签名证书的客户端证书。

然后,我在mmc中的“受信任证书颁发机构”部分安装了自签名证书.

服务器证书和客户端证书安装在mmc的个人部分。

然后,我使用服务器证书将web服务作为HTTP部署到IIS中。

然后,我有了另一个利用web服务的应用程序。它发送带有web服务请求的客户端证书,如下所示:

代码语言:javascript
复制
public static void Main(string[] args)
        {
            X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySubjectName, "client.com", true);

            if (col.Count == 1)
            {
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;

                ClientServices web_service = new ClientServices();
                web_service.ClientCertificates.Add(col[0]);

                try
                {
                    string check = web_service.CheckCertificate();

                    Console.WriteLine(check);
                }
                catch (WebException e)
                {
                    Console.WriteLine(e.Message.ToString());
                }
            }

            else
            {
                Console.WriteLine("The certificate was not found!");
            }
            Console.ReadKey();
        }

在服务器端,我检查客户端证书,如下所示:

代码语言:javascript
复制
[WebMethod]
        public string CheckCertificate()
        {
            string message;

            try
            {
                X509Certificate2 cert = new X509Certificate2(Context.Request.ClientCertificate.Certificate);                

                if (cert != null)
                {
                    message = cert.SerialNumber.ToString();
                }

                else
                {
                    message = "Error: No certificate was found!";
                }
            }
            catch (Exception e)
            {
                message = e.Message.ToString();
            }
            return message;
        }

每当我运行客户端应用程序时,我都会收到以下错误消息:

请求被中止。无法创建SSL/TLS安全通道.

我怎样才能解决这个问题?我被困在这上面已经两天了,所以任何帮助都会受到极大的感谢。

EN

回答 1

Security用户

回答已采纳

发布于 2013-04-28 07:42:39

我解决了问题。我安装了WinHttpCertCfg工具并授予了对私钥的访问权限。对我起作用的命令是:

WinHttpCertCfg.exe -g -c LOCAL_MACHINE\MY -s“-a EVERYONE”

票数 0
EN
页面原文内容由Security提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://security.stackexchange.com/questions/34931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档