c# - 如何创建使用 RsaSsaPssSha256 签名的 JWT

标签 c# jwt rsa-sha256

我正在尝试使用 RsaSsaPssSha256 和我从 keystore 中读取的自签名 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."


我在这里错过了什么?

最佳答案

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

关于c# - 如何创建使用 RsaSsaPssSha256 签名的 JWT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57348047/

相关文章:

c# - 查找图表中点的值

javascript - 如何在xmlhttprequest中发送jwt?

sha256 - SHA-256 不同的结果

oauth-2.0 - 如何使用 RSA SHA-256 哈希对 JWT 进行签名

c# - 从实异常(exception)部将属性设置为 null

c# - 如何将 GameLift 与 Unity3d 集成作为游戏客户端

c# - 等待返回任务的方法 - 永远旋转?

angular - 在 ionic 3 应用程序中使用 JWT 进行身份验证

访问 jwt-decode 对象时出现 typescript 错误