我有一个 Azure 网站实例,需要连接输出到在其他地方运行且使用客户端证书保护的 WCF 服务。
客户端 -> Azure 网站(MVC Controller ) -> 需要客户端证书的 WCF 服务(不是 Azure)
我已获得一个 CER 文件,在本地安装时,该文件允许我的网站连接到 WCF 服务。如何在 Azure 网站上安装/提供此证书?
我在研究此问题时找到的所有文档都是关于在 Azure 中运行时保护 WCF 服务的安全,并且需要安装带有密码的 PFX 文件。我正在尝试执行相反的操作,将 Azure 网站的出站连接到第三方 WCF 服务。
最佳答案
来自: https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/
添加以下应用程序设置:
- 应用设置名称:
WEBSITE_LOAD_CERTIFICATES
- 值:
*
或{CERT_THUMBPRINT}
然后您可以从我的
商店获取证书:
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
// Replace below with yourcert's thumbprint
"E661583E8FABEF4C0BEF694CBC41C28FB81CD870”,
false);
现在,我认为您无法上传 .cer
。
.pfx
似乎是应用服务中唯一接受的格式。
或者如果无需担心私钥,则只需从磁盘加载它。
这也可以让您加载 .cer
(DER 可以工作,也可能是 Base64):
// The path to the certificate.
string Certificate = @"d:\home\site\cert.cer";
// Load the certificate into an X509Certificate object.
X509Certificate cert = X509Certificate.CreateFromCertFile(Certificate);
// Print to console
string result = cert.ToString(true);
Console.WriteLine(result);
在应用服务中工作得很好(这里它在 Kudu console 中运行):
关于c# - 使用来自 Azure 网站实例的客户端证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41065150/