【问题标题】:AuthenticateAsServer won't accept PEM format certificatesAuthenticateAsServer 不接受 PEM 格式证书
【发布时间】:2012-07-02 14:37:55
【问题描述】:
X509CertificateCollection certCollec = 
new X509CertificateCollection(new X509Certificate[1] { xcert});

X509CertificateCollection certCollecpfx = 
new X509CertificateCollection(new X509Certificate[1] { pfxCert });

SSLStream.AuthenticateAsClient(apsHost, certCollec, SslProtocols.Default, false);

certCollec 包含 PEM 格式的证书

certCollecpfx 包含 PFX 格式的证书

AuthenticateAsClient 服务器仅适用于 PFX 格式,即使 pem 和 pfx 的 X509Certificate2 对象具有完全相同的原始数据。

这是为什么?它一直告诉我调用 SSPI 失败:数据格式错误。

为什么不接受 pem 格式?

然后我尝试将 pem 格式导出到 pfx,但它仍然不接受它 - 同样的错误,即使我将它导出到 pfx。

byte[] pemCertBytes = pemCert.Export(X509ContentType.Pfx, "620fpass");
            File.WriteAllBytes(@"C:\test\MyCert.pfx", pemCertBytes);

【问题讨论】:

  • 如果我记得将带有私钥的证书从一种格式转换为另一种格式,您必须使用标志 X509KeyStorageFlags.Exportable 加载证书。

标签: c# ios apple-push-notifications mdm


【解决方案1】:
even though the X509Certificate2 object for the pem and the pfx has exactly the same raw data.

我认为只有在 pem 证书包含实际证书和私钥的情况下才是正确的。此外,它具有特定的标题,即 BEGIN-CERTIFICATEEND-CERTIFICATE 包含实际内容。 pfx 或 pkcs#12 证书包含证书和私钥,可以选择使用密码进行加密。如果您曾经将证书导入 Windows 证书存储区,您可能已经注意到在执行此操作时它会提示您输入密码,这实际上是用于加密证书的私钥。

I then tried to export the pem format into pfx and it still didn't accept it

我建议使用openssl 来执行此操作。一般语法是

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

【讨论】:

    猜你喜欢
    • 2014-07-27
    • 2021-02-12
    • 2011-09-02
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多