作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的解密网络作业中,我使用 .pfx 证书。但为了更加安全,我必须将此证书上传到 Azure 存储并通过 c# 访问它。
任何人都可以提供更多相关信息(链接)吗?
最佳答案
根据您的描述,我假设您可以按照以下步骤上传 PFX 文件并从您的应用访问它。
上传 PFX 证书
登录portal.azure.com ,选择您的应用服务,然后点击“设置 > SSL 证书”,然后点击上传证书,如下添加您的 PFX 证书文件:
添加应用设置
点击应用服务的“设置 > 应用程序设置”部分,添加名为 WEBSITE_LOAD_CERTIFICATES
的应用设置,并将其值设置为您上传的 PFX 证书文件的指纹,如下所示:
从应用程序访问
您可以利用以下代码片段来检索证书,如下所示:
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
“{your-cert's-thumbprint}”,
false);
// Get the first cert with the thumbprint
if (certCollection.Count > 0)
{
X509Certificate2 cert = certCollection[0];
// Use certificate
Console.WriteLine(cert.FriendlyName);
}
certStore.Close();
另外,这里有一篇之前的博客,讲的是在Azure网站应用程序中使用证书,您可以引用here .
关于c# - 如何在Azure中上传pfx证书并在C#中访问和使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45126046/
我是一名优秀的程序员,十分优秀!