![](/img/trans.png)
[英]certMgr.exe not loading the private key of certificate in personal local machine store(Windows 10)
[英]Private key is not loading upon loading from the Certificate Store
RavenDB 4的身份验证需要通过我通过Let's Encrypt创建的证书进行。 我的私钥证书 (.pfx)存储在Azure密钥保管库中。 由于只能上传受密码保护的证书,因此我通过密码使其安全。
通过使用证书指纹来加载证书后,它始终显示它没有私钥,从而使我的RavenDB实例的身份验证过程失败。 既可以通过Windows证书存储在本地使用,也可以在Azure上使用。
我已经尝试使用没有密码的私钥证书 ,然后便可以接收私钥。 但是,这不是解决方案,因为我无法将其上传到Azure。
var certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2 targetClientCertificate;
var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, ravenDbSettings["CertificateThumbPrint"], false);
targetClientCertificate = new X509Certificate2(certCollection[0].GetRawCertData(), ravenDbSettings["CertificatePassword"], X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable); ;
我也通过使用我在某处找到的导出来尝试了
var targetTwo = new X509Certificate2(certCollection[0].Export(X509ContentType.Pfx, ravenDbSettings["CertificatePassword"]));
但后来我得到了
Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException:'密钥在指定状态下无效
我的目标是加载证书的私钥,从而能够在RavenDB上进行身份验证。
您必须使用存储在certCollection
变量中的现有证书。 最后一行(您在其中填充targetClientCertificate
变量)不是必需的,并且如果私钥不可导出,则该行将不起作用。 如果代码需要X509Certificate2
类的现有实例,则它将存储在certCollection
,并将具有关联的私钥链接。
这可能与您创建证书的方式有关。 尝试这个:
下载openssl: http : //gnuwin32.sourceforge.net/packages/openssl.htm
生成证书和私钥: openssl req -new -newkey rsa:1024 -days 365 -nodes -x509 -keyout YourName.key -out YourName.cert
生成pfx文件: openssl pkcs12 -export -inkey YourName.key -in YourName.cert -out YourName.pfx
将 YourName.pfx 导入到商店
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.