【发布时间】:2021-12-07 05:13:40
【问题描述】:
我在创建 X509Certificate2 对象时遇到问题。
private void OpenKey()
{
if (!File.Exists(KeyFile))
{
return;
}
cert = new X509Certificate2(File.ReadAllBytes(KeyFile), KeyPassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
securityKey = new X509SecurityKey(cert);
}
在本地主机上这工作正常,在开发服务器上也是如此,但在生产服务器上我有错误:
Exception: System.Security.Cryptography.CryptographicException: An internal error occurred. at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) at System.Security.Cryptography.X509Certificates.X509Utils.LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle pCertCtx) at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
我在 .NET Framework 4.5.2 上工作。
我能做些什么来解决这个问题?
【问题讨论】:
-
用户可能没有足够的权限将私钥保存在机器存储中。
标签: c# asp.net .net iis x509certificate2