Linux上的ASP.NET Core 6 ReactJS Web App存在IDX10634问题:无法创建Signat



我已将基于ASP.NET 6 ReactJS模板的ASP.NET 6解决方案部署到Linux Cents/Apache托管环境中。

根据下面提供的错误消息,我似乎需要更改签名提供程序的算法,但我不知道该怎么做。

System.NotSupportedException: IDX10634: Unable to create the SignatureProvider.
Algorithm: 'RS256', SecurityKey: 'Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: 'xxxxxxxxxxxx', InternalId: 'xxxxxxx'.' is not supported. The list of supported algorithms is available here: https://aka.ms/IdentityModel/supported-algorithms

我发现了几个常见问题解答,表明要使用ECDSA或类似的方法,但没有真正的例子说明如何在我的解决方案类型中实现这一点,也没有在Program.cs或类似程序中进行修改的例子。

如果能给我一些想法,我将不胜感激!

提前感谢!

您可以使用OpenSSL创建自己的ECDSA密钥,使用:

#Create P256 ECDSA Private key
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -aes256 -out p256-private.pem
# Optionally, if you want to extract the public key:
openssl ec -in p256-private.pem -pubout -out p256-public.pe
# Create certificat file
openssl req -new -x509 -key p256-private-key.pem -days 365 -subj "/CN=MyP256Cert" -out p256-cert.crt
# Crete the PFX file
openssl req -new -x509 -key p256-private-key.pem -days 365 -subj "/CN=MyP256Cert" -out p256-cert.crt

然后你可以在C#中加载它,使用:

var ecdsaCert = new X509Certificate2("es256.pfx", "password");
SecurityKey ecdsaPrivateKey = new ECDsaSecurityKey(ecdsaCert.GetECDsaPrivateKey());

您可以使用以下方法将其添加到IdentityServer:

// Add ES256 (ECDSA using P-256 and SHA-256)
builder.AddSigningCredential(GetECDsaPrivateKey(p256Cert), IdentityServerConstants.ECDsaSigningAlgorithm.ES256);

最新更新