将CER转换为PFX时发生强制转换错误(用于添加到Azure门户)
Azure门户不允许我添加Cer文件。我发现一个帖子说你可以输入名字,你只能在开放对话中输入,但它不起作用 因此,我尝试使用我放在Global.asax中的代码转换该文件。我已将CER文件从C驱动器的根目录复制到我的临时目录中 以下是我得到的代码和错误:将CER转换为PFX时发生强制转换错误(用于添加到Azure门户),azure,Azure,Azure门户不允许我添加Cer文件。我发现一个帖子说你可以输入名字,你只能在开放对话中输入,但它不起作用 因此,我尝试使用我放在Global.asax中的代码转换该文件。我已将CER文件从C驱动器的根目录复制到我的临时目录中 以下是我得到的代码和错误: string file = @"C:\temp\SVRSecureG3.cer"; var cert = System.Security.Cryptography.X509Certificates.X509Certificate
string file = @"C:\temp\SVRSecureG3.cer";
var cert = System.Security.Cryptography.X509Certificates.X509Certificate2.CreateFromCertFile(file);
// Error occurs on the line below, I get : {"Unable to cast object of type 'System.Security.Cryptography.X509Certificates.X509Certificate' to type 'System.Security.Cryptography.X509Certificates.X509Certificate2'."}
var bytes = ((System.Security.Cryptography.X509Certificates.X509Certificate2)cert).Export(System.Security.Cryptography.X509Certificates.X509ContentType.Pfx, "p");
var fs = File.Create(@"C:\temp\SVRSecureG3.pfx");
using (fs)
{
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
}
实际上,我建议您将.cer转换为.pfx。使用OpenSSL可以做到这一点,我已经多次这样做,将证书上载到Azure 下载 用法
感谢您的回复,我们没有密码作为第三方,但是您为PFX创建密码,您不需要从某人那里获得密码。是的,他会的,但是如果没有私钥,他无论如何都无法安装证书。他需要它,否则无法安装证书。