【问题标题】:Windows Azure Management Libraries Certification Error on Web JobsWeb 作业上的 Windows Azure 管理库认证错误
【发布时间】:2014-04-28 00:43:15
【问题描述】:

我构建了一个 Azure Web 作业控制台,它引用了 Windows Azure 管理库。 我尝试使用公共设置方法对我的应用进行身份验证。

该程序在我的本地运行良好,但在 Azure Web Jobs 上失败并出现 X509Certificates 错误。

这就是我为网络工作计划所做的。

  1. https://windows.azure.com/download/publishprofile.aspx下载的发布设置文件

  2. 在控制台应用程序上,通过从设置文件中复制并粘贴订阅 ID 和证书字符串来创建凭据。

    new CertificateCloudCredentials(
        subscriptionId,
        new  509Certificate2(Convert.FromBase64String(base64EncodedCertificate)));
    
  3. 在 Azure Web 作业上部署并尝试“按需运行”。

  4. 错误

    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.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
    at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] data)
    at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)
    

执行时出现异常:

System.Security.Cryptography.CryptographicException, The system cannot find the file specified.

【问题讨论】:

标签: c# .net security azure x509certificate


【解决方案1】:

我建议从这篇博文开始:http://blog.tylerdoerksen.ca/2015/11/29/pfx-certificate-files-and-azure-web-apps/。虽然这篇博客文章是关于 Azure 网站而不是 Azure Webjobs 本身,但我倾向于相信你的问题是因为这个。事实上,我在使用 Azure 网站时遇到了完全相同的问题。

但是,为了使用博文中概述的解决方案,您不能按原样使用发布设置文件中的 certstring。以下是您需要做的:

  1. 通过另一个控制台应用程序,首先创建一个 X509 证书并将其安装在本地计算机的证书存储中。
  2. 以 PFX 格式导出证书并提供密码。
  3. 将此 PFX 证书作为解决方案的一部分包含在内。对于 Azure 网站,我们必须将此文件包含在 App_Data 文件夹中,如果是 Webjob,我们不确定将其包含在哪里。您可以尝试使其出现在 bin 文件夹中。
  4. 阅读此文件并尝试使用博文中指定的语法创建 X509 证书实例(并在此处复制):

    var cert = new X509Certificate2(pfxFile, "myPassword", X509KeyStorageFlags.MachineKeySet);
    

【讨论】:

  • 感谢您的回答。目前,我正在尝试使用 pub 设置。但我会通过创建自己的证书来尝试这种方法,直到找到解决方案。干杯。
猜你喜欢
  • 2010-11-28
  • 1970-01-01
  • 1970-01-01
  • 2015-05-12
  • 1970-01-01
  • 1970-01-01
  • 2021-07-05
  • 2014-09-12
  • 1970-01-01
相关资源
最近更新 更多