【发布时间】:2021-12-07 11:21:48
【问题描述】:
我正在尝试从路径加载证书并在 Windows 服务器上出现内部服务器错误。虽然我在 Windows 10 上执行此操作,但一切正常。
不工作的控制台应用程序代码
var path = args[0];
var password = args[1];
var certificate2 = new X509Certificate2(path, password);
但出现错误
Unhandled exception. Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: An internal error occurred.
at Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(Byte[] rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags)
at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(Byte[] rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password)
at CertCoreTest.Program.Main(String[] args) in C:\Users\Admin\Documents\Visual Studio 2019\Projects\CertTest\CertCoreTest\Program.cs:line 12
破解工作代码(不知道为什么会起作用)
var path = args[0];
var password = args[1];
Chilkat.Cert cert = new Chilkat.Cert();
var success = cert.LoadPfxData(File.ReadAllBytes(path), password);
if (success == false)
{
throw new Exception(cert.LastErrorText);
}
var bytes = cert.ExportToPfxData(password, true);
var ceeert = new X509Certificate2(bytes, password);
如何在不使用 chilkat 库的情况下使其在 windows 服务器上运行?
【问题讨论】:
-
您是否在两个平台上运行完全相同的可执行文件?和相同的证书文件?您是否都以管理员身份运行?
-
是的,我运行的完全一样
-
不知道你在PFX中使用的算法是不是9年前就没有了?
-
一些非常好的建议here。这可能与潜在的权限问题有关。证书可能会存储一些信息以访问用户在服务器(即机器)上没有被授予访问权限的存储。或者按照帖子中的建议开一家商店可能会有所帮助。
-
@user2279379 您能否提供有关该文件的更多详细信息?加密算法、PKCS #12 版本、文件保护类型、...
标签: c# .net windows-server-2012 x509certificate2 chilkat