<legend id='EIKnv'><style id='EIKnv'><dir id='EIKnv'><q id='EIKnv'></q></dir></style></legend>
      <bdo id='EIKnv'></bdo><ul id='EIKnv'></ul>

      <small id='EIKnv'></small><noframes id='EIKnv'>

      <i id='EIKnv'><tr id='EIKnv'><dt id='EIKnv'><q id='EIKnv'><span id='EIKnv'><b id='EIKnv'><form id='EIKnv'><ins id='EIKnv'></ins><ul id='EIKnv'></ul><sub id='EIKnv'></sub></form><legend id='EIKnv'></legend><bdo id='EIKnv'><pre id='EIKnv'><center id='EIKnv'></center></pre></bdo></b><th id='EIKnv'></th></span></q></dt></tr></i><div id='EIKnv'><tfoot id='EIKnv'></tfoot><dl id='EIKnv'><fieldset id='EIKnv'></fieldset></dl></div>

      <tfoot id='EIKnv'></tfoot>

      JwtSecurityToken 理解与异常

      时间:2023-06-03
      • <i id='GIagu'><tr id='GIagu'><dt id='GIagu'><q id='GIagu'><span id='GIagu'><b id='GIagu'><form id='GIagu'><ins id='GIagu'></ins><ul id='GIagu'></ul><sub id='GIagu'></sub></form><legend id='GIagu'></legend><bdo id='GIagu'><pre id='GIagu'><center id='GIagu'></center></pre></bdo></b><th id='GIagu'></th></span></q></dt></tr></i><div id='GIagu'><tfoot id='GIagu'></tfoot><dl id='GIagu'><fieldset id='GIagu'></fieldset></dl></div>
        <tfoot id='GIagu'></tfoot>
        1. <small id='GIagu'></small><noframes id='GIagu'>

            <tbody id='GIagu'></tbody>

            <legend id='GIagu'><style id='GIagu'><dir id='GIagu'><q id='GIagu'></q></dir></style></legend>

                <bdo id='GIagu'></bdo><ul id='GIagu'></ul>
              • 本文介绍了JwtSecurityToken 理解与异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我对 JwtSecurityTokens 还很陌生,我试图了解它的不同方面,以及整个 claimsidentityclaimprincipal,但那是另一回事了.

                我尝试使用以下代码在 C# 中生成令牌:

                private const string SECRET_KEY = "abcdef";私有静态只读 SymmetricSecurityKey SIGNING_KEY = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(SECRET_KEY));公共静态字符串 GenerateToken(string someName){var token = new JwtSecurityToken(索赔:新索赔[]{新声明(ClaimTypes.Name,someName),},notBefore: 新的 DateTimeOffset(DateTime.Now).DateTime,过期:新的 DateTimeOffset(DateTime.Now.AddMinutes(60)).DateTime,签名证书:新的签名证书(SIGNING_KEY,SecurityAlgorithms.HmacSha256));返回新的 JwtSecurityTokenHandler().WriteToken(token);}

                <块引用>

                我遵循了 Youtube 上的教程,但我不确定我是否理解JwtSecurityToken 中的不同部分.另外,当我执行通过控制器的代码只是为了尝试返回一个令牌,它返回一个错误,说:IDX10603:解密失败.密钥尝试:'[PII 被隐藏]'".

                感谢任何帮助.

                解决方案

                算法 HS256 要求 SecurityKey.KeySize 大于 128 位,而您的密钥只有 48 位.通过添加至少还有 10 个符号.至于PII 被隐藏"部分,它是作为 GDPR 合规性工作的一部分,以隐藏日志中的任何堆栈或变量信息.您应该启用其他详细信息:

                IdentityModelEventSource.ShowPII = true;

                I'm fairly new to JwtSecurityTokens, and I try to understand the different aspects of it and furhtermore the whole claimsidentity and claimprincipal, but that's another story.

                I try to generate a token in C# by using the following code:

                private const string SECRET_KEY = "abcdef";
                private static readonly SymmetricSecurityKey SIGNING_KEY = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(SECRET_KEY));
                
                    public static string GenerateToken(string someName)
                    {
                        var token = new JwtSecurityToken(
                            claims: new Claim[]
                            {
                                new Claim(ClaimTypes.Name, someName), 
                            },
                            notBefore: new DateTimeOffset(DateTime.Now).DateTime,
                            expires: new DateTimeOffset(DateTime.Now.AddMinutes(60)).DateTime,
                            signingCredentials: new SigningCredentials(SIGNING_KEY, SecurityAlgorithms.HmacSha256)
                        );
                
                        return new JwtSecurityTokenHandler().WriteToken(token);
                    }
                

                I followed a tutorial on Youtube, but I'm not sure I understand the different parts in the JwtSecurityToken. In addition, when I execute the code through a controller just to try to return a token, it returns an error, saying: "IDX10603: Decryption failed. Keys tried: '[PII is hidden]'".

                Any help is appreciated.

                解决方案

                The algorithm HS256 requires the SecurityKey.KeySize to be greater than 128 bits and your key has just 48. Extend it by adding at least 10 more symbols. As for "PII is hidden" part, it was done as a part of GDPR compliance effort to hide any stack or variable info in logs. You should enable additional details with:

                IdentityModelEventSource.ShowPII = true;
                

                这篇关于JwtSecurityToken 理解与异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:JWT 如何添加自定义声明和解码声明 下一篇:使用 x509 证书签署 JWT 令牌时遇到问题

                相关文章

                最新文章

              • <i id='g0s3G'><tr id='g0s3G'><dt id='g0s3G'><q id='g0s3G'><span id='g0s3G'><b id='g0s3G'><form id='g0s3G'><ins id='g0s3G'></ins><ul id='g0s3G'></ul><sub id='g0s3G'></sub></form><legend id='g0s3G'></legend><bdo id='g0s3G'><pre id='g0s3G'><center id='g0s3G'></center></pre></bdo></b><th id='g0s3G'></th></span></q></dt></tr></i><div id='g0s3G'><tfoot id='g0s3G'></tfoot><dl id='g0s3G'><fieldset id='g0s3G'></fieldset></dl></div>

                    <bdo id='g0s3G'></bdo><ul id='g0s3G'></ul>

                    <tfoot id='g0s3G'></tfoot>

                    <small id='g0s3G'></small><noframes id='g0s3G'>

                    <legend id='g0s3G'><style id='g0s3G'><dir id='g0s3G'><q id='g0s3G'></q></dir></style></legend>