【问题标题】:Loading a certificate as embedded resource in an assembly将证书作为嵌入资源加载到程序集中
【发布时间】:2017-11-27 09:54:08
【问题描述】:

我已将 PFX 文件添加为程序集中的嵌入式资源,以使用证书对 JWT 令牌进行签名。我将 pfx 作为流加载并读取所有字节并使用 X509Certificate2 加载私钥

public X509Certificate2(byte[] rawData, string password)

在调试/发布的开发机器上工作正常,但当部署到天蓝色应用服务或构建机器时,我看到“错误数据”错误。

非常感谢任何帮助。 谢谢

【问题讨论】:

  • 由于我似乎无法从我的嵌入式资源中读取我的 .pfx 文件,您能否发布有关如何执行此操作的代码?如有必要,我可以问一个 SO 问题
  • 没关系,让它工作

标签: c# azure certificate embedded-resource x509certificate2


【解决方案1】:

您似乎想从 Azure App Service Web 应用上的应用访问证书,您可以将您的证书上传到 Azure 网站中的证书集合,然后从您网站的个人证书存储中在您的 Web 应用程序中使用它。

上传证书

添加名为 WEBSITE_LOAD_CERTIFICATES 的应用设置,其值设置为证书的指纹

在申请中消费证书

X509Certificate2 retVal = null;

X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);

X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);

if (certCollection.Count > 0)
{
    retVal = certCollection[0];
}

certStore.Close();

详情请查看:Using Certificates in Azure Websites Applications

【讨论】:

  • 谢谢!是的,我错过了这重要的一步
猜你喜欢
  • 2011-10-17
  • 1970-01-01
  • 2018-10-15
  • 1970-01-01
  • 2010-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多