调用WriteToken方法生成jwttoken报错:Unable to create KeyedHashAlgorithm for algorithm 'HS256', the key size must be greater than: '256' bits
System.ArgumentOutOfRangeException:“IDX10720: Unable to create KeyedHashAlgorithm for algorithm 'HS256', the key size must be greater than: '256' bits, key has '224' bits. Arg_ParamName_Name”
原因
无法创建HS256加密算法,因为提供的加密数据太短。生成jwt需要Issuer/Audience两个重要参数,把参数值弄长一点。
解决方案
jwt 参数在 appsettings.json 定义的,原来的定义(太短了,报错):
C# 全选
"jwt": { //JWT Token认证
"Secret": "B7AC9D-09D3-4DF7-A74zFF", //jwt secret key
"Issuer": "www.csframework.com", //发行方
"Audience": "CSFramework.License", //接收方
"AccessExpireHours": 24000, //单位(小时),参考:JwtHelper.WriteJwtToken()
"RefreshExpireHours": 24000 //单位(小时)
}
把参数值弄长一点:
C# 全选
"jwt": { //JWT Token认证
"Secret": "KEY-202412-B7AC9D-09D3-4DF7-A74zBZt", //jwt secret key
"Issuer": "www.csframework.com|C/S框架网", //发行方
"Audience": "CSFramework.License|软件授权注册系统", //接收方
"AccessExpireHours": 24000, //单位(小时),参考:JwtHelper.WriteJwtToken()
"RefreshExpireHours": 24000 //单位(小时)
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网