gpt4 book ai didi

c# - 如何在Azure中上传pfx证书并在C#中访问和使用它?

转载 作者:行者123 更新时间:2023-12-03 04:50:51 26 4
gpt4 key购买 nike

在我的解密网络作业中,我使用 .pfx 证书。但为了更加安全,我必须将此证书上传到 Azure 存储并通过 c# 访问它。

任何人都可以提供更多相关信息(链接)吗?

最佳答案

根据您的描述,我假设您可以按照以下步骤上传 PFX 文件并从您的应用访问它。

上传 PFX 证书

登录portal.azure.com ,选择您的应用服务,然后点击“设置 > SSL 证书”,然后点击上传证书,如下添加您的 PFX 证书文件:

enter image description here

添加应用设置

点击应用服务的“设置 > 应用程序设置”部分,添加名为 WEBSITE_LOAD_CERTIFICATES 的应用设置,并将其值设置为您上传的 PFX 证书文件的指纹,如下所示:

enter image description here

从应用程序访问

您可以利用以下代码片段来检索证书,如下所示:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com