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

问题描述:

在我的Web解密工作中,我使用了.pfx证书。但为了更安全的目的,我必须将此证书上传到Azure存储并通过c#访问它。如何上传Azure中的pfx证书并访问并在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