問題描述
我正在嘗試實現 JWT 令牌,但一直遇到以下異常:IDX10640:不支持算法:'http://www.w3.org/2001/04/xmldsig-more#hmac-sha256' 嘗試將令牌寫入壓縮 json 字符串時.
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?
更新 1:
上述錯誤發生在 "System.IdentityModel.Tokens.Jwt": "5.0.0-beta7-208241120"
The error above occurs with "System.IdentityModel.Tokens.Jwt": "5.0.0-beta7-208241120"
更新 2:
更新代碼
推薦答案
我們目前不支持對稱密鑰.希望能盡快實現.
We don't have support for symmetric keys right now. Hope to get that in soon.
這篇關于DNX Core 5.0 JwtSecurityTokenHandler“IDX10640:不支持算法:'http://www.w3.org/2001/04/xmldsig-more#hmac-sha256'"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!