“无法找到请求的对象”在.Net Core中将*私钥*加载到X509Certificate2中时出错

时间:2019-03-15 13:55:26

标签: .net-core x509certificate2

我们正在使用.Net Core应用程序中的System.Security.Cryptography.X509Certificates组件,并在尝试加载私钥时遇到此错误。证书所需的唯一功能是解密字符串并检查NotAfter值。出错的代码行是:

var cert = new X509Certificate2(privateKeyByteArr);

例外:

    Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException
  HResult=0x80092009
  Message=Cannot find the requested object
 Source=System.Security.Cryptography.X509Certificates  Cannot find the requested object
  StackTrace:
   at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(Byte[] rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] data)
   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)
   at Telematics.CommonUtilities.Services.RSACryptoService.DecryptKey(String key, Byte[] privateKeyByteArr) in D:\Users\I25266\Source\Repos\common utils feature b\telematics.commonutilities\Telematics.CommonUtilities\Services\RSACryptoService.cs:line 383

使用公钥可以使用相同的方法,并且可以将BouncyCastle成功使用相同的私钥。我也尝试过X509Certificate2Collection Import()方法-同样的错误。即使我们有解决方法,我仍想使用本机.Net组件。

任何建议或解释都将受到欢迎。

0 个答案:

没有答案