【发布时间】:2017-02-03 11:38:06
【问题描述】:
执行提取公钥的行时,会发送一个 LDAP 请求:
this.certificate = new X509Certificate2(buffer);
System.Security.Cryptography.X509Certificates.PublicKey key = this.certificate.PublicKey;
50 0.853745000 xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx LDAP 404 searchRequest(1) "" baseObject
...我相信这是对当前登录用户的身份验证。我真的需要避免这个调用,因为在客户系统上,由于网络配置,这会导致很长的延迟。
我假设它正在尝试围绕某种密钥存储进行一些身份验证,但在这种情况下,证书全部包含在提供的缓冲区中,我想要的只是在不发送此请求的情况下使用密钥.
我真正想要的只是从证书中的私钥创建一个 RSACryptoServiceProvider。我尝试了一些我在这里找到的涉及 GetPrivateKey 的方法,但都无法正常工作。
提前致谢!
编辑测试程序:
static void Main( string[] args )
{
var certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(@"E:\Temp\Cert.cer");
System.Security.Cryptography.X509Certificates.PublicKey key = certificate.PublicKey;
}
我测试的证书可以在这里找到:Cert.cer
是的,这不是最强的签名或密钥,在我得到 cmets 之前!
再次感谢。
编辑:我实际上通过使用 BouncyCastle 的建议解决了这个问题。我用它来解析证书:
X509CertificateParser parser = new X509CertificateParser();
Org.BouncyCastle.X509.X509Certificate cert = parser.ReadCertificate(buffer);
然后我提取模数和指数并将它们推送到 Microsoft RSAParameters:
RsaKeyParameters key = (RsaKeyParameters)cert.GetPublicKey();
// Construct a microsoft RSA crypto service provider using the public key in the certificate
RSAParameters param = new RSAParameters();
param.Exponent = key.Exponent.ToByteArrayUnsigned();
param.Modulus = key.Modulus.ToByteArrayUnsigned();
然后我可以由此构造 Microsoft RSACryptoServiceProvider:
using (RSACryptoServiceProvider provider = new RSACryptoServiceProvider())
{
provider.ImportParameters(param);
byte[] rsaBlock = provider.Encrypt(preMasterSecret, false);
this.Client.Writer.Write(rsaBlock);
}
【问题讨论】:
-
您确定此行执行 LDAP 查询吗?你能告诉我们更多涉及的代码吗?
-
我用一个简单的测试程序和自签名证书复制了这个。我会用测试代码更新问题。
-
是的,当我跨过第二行时,我在 Wireshark 中得到以下信息:link
-
使用 BouncyCastle 作为解决方法。但如果你碰巧找到了这个 LDAP 请求的原因,我很想知道。
-
我在微软支持论坛上问过这个问题。我正在考虑升级它并在那里获得一些官方支持。不过,我一定会看看 BouncyCastle,谢谢!
标签: c# x509certificate2 rsacryptoserviceprovider