DNX核心5.0 JwtSecurityTokenHandler" IDX10640:不支持算法:“http://www.w3.org/2001/04/xmldsig-more#hmac-sha256'" [英] DNX Core 5.0 JwtSecurityTokenHandler "IDX10640: Algorithm is not supported: 'http://www.w3.org/2001/04/xmldsig-more#hmac-sha256'"

查看:322
本文介绍了DNX核心5.0 JwtSecurityTokenHandler" IDX10640:不支持算法:“http://www.w3.org/2001/04/xmldsig-more#hmac-sha256'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现JWT令牌,但保持运行到以下异常:IDX10640:不支持算法:的 http://www.w3.org/2001/04/xmldsig-more#hmac-sha256 试图写令牌紧凑JSON字符串时。

 常量字符串发行人=发行人; 
常量字符串观众=观众;
字节[] = keyForHmacSha256新的字节[32];
新的随机()的nextBytes(keyForHmacSha256);

变种索赔=新的List<权利要求GT; {新的索赔(DEVICEID,12)};
变种现在= DateTime.UtcNow;
变种期满= now.AddHours(1);
变种signingCredentials =新SigningCredentials(
新SymmetricSecurityKey(keyForHmacSha256),
SecurityAlgorithms.HmacSha256Signature,SecurityAlgorithms.Sha256Digest);

变种令牌=新JwtSecurityToken(发行人,观众,索赔,目前,过期,signingCredentials);
返回_tokenHandler.WriteToken(标记);

在解决这个任何想法?



更新1:



错误上面System.IdentityModel.Tokens.Jwt的发生:5.0.0-beta7-208241120



更新2:



更新代码


< DIV CLASS =h2_lin>解决方案

我们没有为对称密钥的支持现在。希望能得到在不久。


I'm trying to implement JWT tokens but keep running into the following exception: IDX10640: Algorithm is not supported: 'http://www.w3.org/2001/04/xmldsig-more#hmac-sha256' when trying to write the token to compact json string.

const string issuer = "issuer";
const string audience = "audience";
byte[] keyForHmacSha256 = new byte[32];
new Random().NextBytes(keyForHmacSha256);

var claims = new List<Claim> { new Claim("deviceId", "12") };
var now = DateTime.UtcNow;
var expires = now.AddHours(1);
var signingCredentials = new SigningCredentials(
    new SymmetricSecurityKey(keyForHmacSha256), 
    SecurityAlgorithms.HmacSha256Signature, SecurityAlgorithms.Sha256Digest);

var token = new JwtSecurityToken(issuer, audience, claims, now, expires, signingCredentials);
return _tokenHandler.WriteToken(token);

Any ideas on solving this?

Update 1:

The error above occurs with "System.IdentityModel.Tokens.Jwt": "5.0.0-beta7-208241120"

Update 2:

Updated code

解决方案

We don't have support for symmetric keys right now. Hope to get that in soon.

这篇关于DNX核心5.0 JwtSecurityTokenHandler&QUOT; IDX10640:不支持算法:“http://www.w3.org/2001/04/xmldsig-more#hmac-sha256'&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆