5

我正在尝试使用 RsaSsaPssSha256 使用我从密钥库中读取的自签名 X509certificate2 对 JWToken 进行签名。

使用.net 4.61;

  1. 尝试使用Microsoft 的System.IdentityModel.Tokens.Jwt
SecurityTokenDescriptor tokenDescriptor = new SecurityTokenDescriptor
{
    Subject = ,
    SigningCredentials = new SigningCredentials(privateKey, SecurityAlgorithms.RsaSsaPssSha256Signature),  
    Expires = DateTime.UtcNow.AddMinutes(expirationMinutes),
};

并得到以下错误:

"IDX10634: Unable to create the SignatureProvider.\nAlgorithm: 'PS256', SecurityKey: 'Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: 'xxxxxxxxxxxxxxxxxxxxxxxxxx', InternalId: 'xxxxx-xxxxxx-xxxx-xxxxxx'.'\n is not supported. The list of supported algorithms is available here: https://aka.ms/IdentityModel/supported-algorithms"

不用说 SecurityAlgorithms.RsaSha256 正在按预期工作。

2.尝试使用Jose-JWT模块,报错:

"RsaUsingSha with PSS padding alg expects key to be of CngKey type."


我在这里想念什么?

4

1 回答 1

1

在从 .NET 4.60 升级到 4.61 时,这是使用 RsaSsaPssSha256 所必需的,我删除了 System.IdentityModel.Tokens.Jwt 包并重新安装它们(即使它是同一个 dll 文件)。现在一切都按预期工作。

于 2019-08-08T11:45:09.843 回答