我有一个.cer文件,其中包含我需要的公钥,以便测试针对AD FS的身份验证。我可以轻松地将它添加到解决方案中现有的Web.config(设置signingCertificate fileName)中的MVC示例中,它似乎可以工作,但我找不到任何方法来添加AspNetCore2项目。
我找到的最接近的是SigningServiceCertificate,但它只有一个getter,我在另一个线程中读到它应该以某种方式将公钥添加到SigningKeys集合中,我只是无法弄清楚如何。
谢谢!
我不确定你问的是什么,但我使用Sustainsys证书,我使用以下行:
var idp = new Sustainsys.Saml2.IdentityProvider(new entityId("https://sso.acme.com"), opt.SPOptions) { ... insert properties ... }
idp.SigningKeys.AddConfiguredKey(new X509Certificate2("customer-certificate.cer"));
opt.SPOptions.ServiceCertificates.Add(EncryptionHelper.GetX509Certificate2("INSERT-THUMBPRINT-OF-YOUR-CERTIFICATE"));
EncryptionHelper.GetX509Certificate2
是一个自定义助手,我写的是为了阅读我的证书。
这是EncryptionHelper
的代码 - 我在网上的许多例子之一的背面制作了它。
public static X509Certificate2 GetX509Certificate2(string thumbprint)
{
X509Certificate2 retVal = null;
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certCollection = store.Certificates;
var signingCert = certCollection.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (signingCert.Count > 0)
{
retVal = signingCert[0];
}
return retVal;
}
请注意,如果您在Azure中运行此操作,则还需要使用这些说明将指纹添加到应用程序设置 - https://docs.microsoft.com/en-us/azure/app-service/app-service-web-ssl-cert-load
您可以按照这些说明找到指纹 - https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-retrieve-the-thumbprint-of-a-certificate