我想使用自签名证书来测试这个实现。我正在使用MVC实现,并且正在运行The remote server returned an error: (500) Internal Server Error。
调试显示,这个错误发生在line 36: ComputeSignature()的Saml2SignedXml.ComputeSignature(...)中,它是从微软的SignedMxl继承过来的,我无法进入它。
Saml2Configuration.SigningCertificate显示了HasPrivateKey = true,但PrivateKey属性出现错误:Saml2Configuration.SigningCertificate.PrivateKey抛出了System.NotSupportedException类型的异常。
在使用provide ITFoxtec证书时,我在同一属性中看到了私钥。
我之所以使用自签名证书,是因为MVC证书会导致tfoxtec.identity.saml2.testidpcore_Certificate.pfx中的Incorrect URI format错误。
老实说,我不认为这是一个代码问题,而是一个证书问题,但我不确定在这一点上应该从哪里看。
发布于 2021-08-20 08:41:37
您可能需要使用另一个自签名证书。
可以在.NET核心或.NET 5.0中创建自签名证书,如下所示:
/// <summary>
/// Create self-signed certificate with subject name. .
/// </summary>
/// <param name="subjectName">Certificate subject name, example: "CN=my-certificate, O=some-organisation".</param>
/// <param name="expiry">Certificate expiry, default 365 days.</param>
public static Task<X509Certificate2> CreateSelfSignedCertificateAsync(this string subjectName, TimeSpan? expiry = null)
{
using (var rsa = RSA.Create(2048))
{
var certRequest = new CertificateRequest(subjectName, rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
certRequest.CertificateExtensions.Add(
new X509BasicConstraintsExtension(false, false, 0, false));
certRequest.CertificateExtensions.Add(
new X509SubjectKeyIdentifierExtension(certRequest.PublicKey, false));
certRequest.CertificateExtensions.Add(
new X509KeyUsageExtension(
X509KeyUsageFlags.DigitalSignature | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyAgreement,
false));
var now = DateTimeOffset.UtcNow;
return Task.FromResult(certRequest.CreateSelfSigned(now.AddDays(-1), now.Add(expiry ?? TimeSpan.FromDays(365))));
}
}该代码来自ITfoxtec.Identity X509Certificate2Extensions.cs,并且该代码例如用于FoxIDs。
https://stackoverflow.com/questions/68857190
复制相似问题