【发布时间】:2020-02-14 08:33:51
【问题描述】:
我正在尝试在 Azure 函数中用 C# 初始化 x509Certificate2 类的新实例,如下所示:
X509Certificate2 cert = new X509Certificate2((certPath + @"/integration_certificate.pfx"), "pw", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet| X509KeyStorageFlags.Exportable);
当我在本地执行该函数时,这工作正常,但是当它在 Azure 上执行时,我收到以下错误:
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The specified network password is not correct
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)
我在 Kudu 上使用了 OpenSSL 来检查我是否使用了正确的密码,并且可以检查。我能够阅读有关证书的信息并且一切看起来都正确。
我也尝试将证书上传到 Azure(看起来是正确的做法),但没有将其包含在源代码中,但我也无法让它工作,因为私钥只有 1024 位长所以 Azure 不接受它。证书是由第三方生成的,所以我认为我不可能以不同的方式生成证书。
有人有什么建议吗?顺便说一句,我目前正在使用 .NET 标准 2.0 作为目标框架。
【问题讨论】:
-
是托管窗口吗?
/作为目录分隔符看起来很奇怪。进程是否有权访问 pfx 文件? -
主机是 windows 是的(操作系统版本:Microsoft Windows NT 10.0.14393.0)。当进程找不到证书时,我收到了不同的错误消息,因此看起来证书已找到。证书位于 home/site/wwwroot 目录下,所以我认为该进程也应该可以访问它?
标签: c# azure azure-functions .net-standard x509certificate2