Encryption Asp.Net Core Jwt access_令牌签名和加密
TLDR;我试图了解Jwt中间件如何能够识别我使用以下签名/加密方案对令牌进行了签名和加密:Encryption Asp.Net Core Jwt access_令牌签名和加密,encryption,asp.net-core-3.1,jwt-auth,c#-8.0,Encryption,Asp.net Core 3.1,Jwt Auth,C# 8.0,TLDR;我试图了解Jwt中间件如何能够识别我使用以下签名/加密方案对令牌进行了签名和加密: SigningCredentials TokenSigningKey = new SigningCredentials( "MySignatureSecurityKey", SecurityAlgorithms.HmacSha512); EncryptingCredentials TokenEncryptingKey = new EncryptingCredentials( &quo
SigningCredentials TokenSigningKey = new SigningCredentials( "MySignatureSecurityKey", SecurityAlgorithms.HmacSha512);
EncryptingCredentials TokenEncryptingKey = new EncryptingCredentials( "MyEncryptionSecurityKey", JwtConstants.DirectKeyUseAlg, SecurityAlgorithms.Aes256CbcHmacSha512 );
在我的Startup.cs
ConfigureServices
方法中,我已将我的服务配置为AddAuthentication(选项)。AddJwtBearer:
services.AddAuthentication( options =>
{
...
} )
.AddJwtBearer( options =>
{
...
options.TokenValidationParameters =
new TokenValidationParameters
{
...
IssuerSigningKey = "MySignatureSecurityKey"
TokenDecryptionKey = "MyEncryptionSecurityKey"
...
};
} );
我不需要配置签名/加密方案,我只是将要使用的密钥传递给它。我只在实际对令牌进行签名/加密时配置签名/加密方案,而该令牌与中间件之间没有连接
此外,对于是否正确定义或在何处找到关于当前最佳实践配置的文档的任何建议,我们将不胜感激:
SigningCredentials TokenSigningKey = new SigningCredentials( "MySignatureSecurityKey", SecurityAlgorithms.HmacSha512);
EncryptingCredentials TokenEncryptingKey = new EncryptingCredentials( "MyEncryptionSecurityKey", JwtConstants.DirectKeyUseAlg, SecurityAlgorithms.Aes256CbcHmacSha512 );
我不得不从网络上的各种零碎信息中拼凑出来,因为文档非常粗糙。哦,天哪,真不敢相信我错过了它。当我在应用加密后检查访问令牌时,我一定是错误地解码了它,因为我刚刚又做了一次,而答案就在我面前 access_令牌的第一部分如下所示:
eyjhbgcioijkaxiilcjlbmmioijbmju2q0jdlutnteyiwiidhlwijoislduin0..
解码后,它看起来像这样:
{“alg”:“dir”,“enc”:“A256CBC-HS512”,“typ”:“JWT”}
荷马-辛普森总力矩
因此,要回答这个问题:
Jwt中间件获取加密令牌(它被表示为承载令牌
),通过解码第一部分(见上文),它可以看到以下内容: