带有私钥的商店中的X509Certificate2

编程入门 行业动态 更新时间:2024-10-23 23:21:02
本文介绍了带有私钥的商店中的X509Certificate2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有私钥的X509Certificate2,无法使用以下代码从Windows商店导出:

I have a X509Certificate2 with private key NOT exportable from the Windows store with this code:

X509Certificate2 oCertificato = null; X509Store my = new X509Store(StoreName.My, StoreLocation.CurrentUser); my.Open(OpenFlags.ReadOnly); System.Security.Cryptography.RSACryptoServiceProvider csp = null; foreach (X509Certificate2 cert in my.Certificates) { if (cert.SerialNumber.Trim() == cSerial) { csp = (System.Security.Cryptography.RSACryptoServiceProvider)cert.PrivateKey; oCertificato = cert; break; } }

当我将证书与Web服务一起使用时,Windows会询问私钥. 问:如何将私钥发送到证书?

When I use the certificate with a web service Windows ask the private key. Question: How can I send the private key to certificate?

致谢.

EDIT :这是将连接作为Web服务的功能:

EDIT: This is the function with the connection as the web service:

string cEndPoint = Leo.myendpoint(); ServicePointManager.ServerCertificateValidationCallback = CertificateHandler; datiOperatore DataOp = Leo.OperatorData();//Operator data request from system (it's ok) datiApplicativo DataApp = Leo.AppData();//program data request from system (it's ok) var b = new CustomBinding(); var sec = new AsymmetricSecurityBindingElement( new X509SecurityTokenParameters(X509KeyIdentifierClauseType.Any, SecurityTokenInclusionMode.Never), new X509SecurityTokenParameters(X509KeyIdentifierClauseType.Any, SecurityTokenInclusionMode.AlwaysToRecipient)); sec.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10; sec.SecurityHeaderLayout = SecurityHeaderLayout.Strict; sec.IncludeTimestamp = true; sec.SetKeyDerivation(false); sec.KeyEntropyMode = System.ServiceModel.Security.SecurityKeyEntropyMode.ServerEntropy; sec.EnableUnsecuredResponse = true; b.Elements.Add(sec); b.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8)); b.Elements.Add(new HttpsTransportBindingElement()); EndpointAddress ea = new EndpointAddress(cEndPoint); oClient = new CVPClient(b, ea); X509Certificate2 certSigned = Leo.GetSignedCert();//HERE IS THE REQUEST OF PRIVATE KEY X509Certificate2 certUnsigned = Leo.GetUnSignedCertificate(); oClient.ClientCredentials.ClientCertificate.Certificate = certSigned; oClient.ClientCredentials.ServiceCertificate.DefaultCertificate = certUnsigned;

推荐答案

我正在解决问题:

string cPin = "12345"; System.Security.SecureString SecurePIN = new System.Security.SecureString(); foreach (char ch in cPin) { SecurePIN.AppendChar(ch); } var rsa = (RSACryptoServiceProvider)certSigned.PrivateKey; string ContinerName = rsa.CspKeyContainerInfo.KeyContainerName; string CspName = rsa.CspKeyContainerInfo.ProviderName; int CspType = rsa.CspKeyContainerInfo.ProviderType; CspParameters csp = new CspParameters(CspType, CspName, ContinerName, new System.Security.AccessControl.CryptoKeySecurity(), SecurePIN); RSACryptoServiceProvider CSP = new RSACryptoServiceProvider(csp);

我希望它对其他人有用

更多推荐

带有私钥的商店中的X509Certificate2

本文发布于:2023-11-05 08:27:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560364.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:商店

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!