在 Monodevelopment 中编写 JSON Web 令牌的异常IDX10632



以下代码是在Windows中使用VS编写的,它似乎在Windows中运行良好。

List<Claim> claimsList;
InMemorySymmetricSecurityKey key;
// fill claims and key with data
var token = new JwtSecurityToken
(
    claims: claimsList,
    signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature, SecurityAlgorithms.Sha256Digest)
);
var tokenHandler = new JwtSecurityTokenHandler();
string tokenStr = tokenHandler.WriteToken(token);

在 Ubuntu 中的 MonoDevelop 上测试时,它会在tokenHandler.WriteToken(token)失败,并显示以下消息:

System.InvalidOperationException : IDX10632: SymmetricSecurityKey.GetKeyedHashAlgorithm( 'http://www.w3.org/2001/04/xmldsig-more#hmac-sha256' ) threw an exception.
SymmetricSecurityKey: 'System.IdentityModel.Tokens.InMemorySymmetricSecurityKey'
SignatureAlgorithm: 'http://www.w3.org/2001/04/xmldsig-more#hmac-sha256', check to make sure the SignatureAlgorithm is supported.
Exception: 'System.NotSupportedException: Specified method is not supported.
  at System.IdentityModel.Tokens.InMemorySymmetricSecurityKey.GetKeyedHashAlgorithm (System.String algorithm) <0x40200b40 + 0x0008b> in <filename unknown>:0 
  at System.IdentityModel.Tokens.SymmetricSignatureProvider..ctor (System.IdentityModel.Tokens.SymmetricSecurityKey key, System.String algorithm) <0x40200350 + 0x000c7> in <filename unknown>:0 '.
  ----> System.NotSupportedException : Specified method is not supported.

我在Google或StackOverflow上没有找到太多关于这个的信息,也没有想到我可以尝试的其他方法。它是否依赖于需要安装的某些外部资源或软件包?我已经确保安装了OpenSSL。

这似乎是相关的,但是我没有使用Katana或OpenID,这与对称与非对称无关。

这似乎是 Mono 中的一个错误/缺陷。它早在 2015 年就被报道过,但不幸的是,截至目前(2017 年 9 月(,它仍未修复。

最新更新