1. <small id='mYibT'></small><noframes id='mYibT'>

      <i id='mYibT'><tr id='mYibT'><dt id='mYibT'><q id='mYibT'><span id='mYibT'><b id='mYibT'><form id='mYibT'><ins id='mYibT'></ins><ul id='mYibT'></ul><sub id='mYibT'></sub></form><legend id='mYibT'></legend><bdo id='mYibT'><pre id='mYibT'><center id='mYibT'></center></pre></bdo></b><th id='mYibT'></th></span></q></dt></tr></i><div id='mYibT'><tfoot id='mYibT'></tfoot><dl id='mYibT'><fieldset id='mYibT'></fieldset></dl></div>
    2. <legend id='mYibT'><style id='mYibT'><dir id='mYibT'><q id='mYibT'></q></dir></style></legend>
      • <bdo id='mYibT'></bdo><ul id='mYibT'></ul>
      <tfoot id='mYibT'></tfoot>
    3. 如何加密 JWT 安全令牌?

      时间:2023-06-03

          <tbody id='ahda4'></tbody>

        • <small id='ahda4'></small><noframes id='ahda4'>

            • <bdo id='ahda4'></bdo><ul id='ahda4'></ul>

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

              1. 本文介绍了如何加密 JWT 安全令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我需要通过签名和加密来保护我的网络令牌.我写了下一行代码:

                I need to secure my web-token with signing and encryption. I wrote the next lines of code:

                var tokenHandler = new JwtSecurityTokenHandler();
                var tokenDescriptor = new SecurityTokenDescriptor
                {
                      Subject = new ClaimsIdentity(new[]
                         {
                             new Claim(ClaimTypes.Name, owner.Name),
                             new Claim(ClaimTypes.Role, owner.RoleClaimType),
                             new Claim("custom claim type", "custom content")
                         }),
                      TokenIssuerName = "self",
                      AppliesToAddress = "http://www.example.com",
                      Lifetime = new Lifetime(now, now.AddSeconds(60 * 3)),
                      EncryptingCredentials = new X509EncryptingCredentials(new X509Certificate2(cert)),
                      SigningCredentials = new X509SigningCredentials(cert1)
                };
                var token = (JwtSecurityToken)tokenHandler.CreateToken(tokenDescriptor);            
                var tokenString = tokenHandler.WriteToken(token);
                

                所以,我使用了一些由 makecert.exe 生成的证书.然后我用另一个 JwtSecurityTokenHandler 读取令牌字符串:

                So, I am using some certificates, generated with makecert.exe. Then I read token string with another JwtSecurityTokenHandler:

                var tokenHandlerDecr = new JwtSecurityTokenHandler();
                var tok = tokenHandlerDecr.ReadToken(tokenString);
                

                并且令牌内容未加密(我可以在调试器下的 tok 变量中看到 json).我究竟做错了什么?如何加密令牌数据?

                And token content is not encrypted (I can see json in tok variable under debugger). What am I doing wrong? How to encrypt token data?

                推荐答案

                我的理解是微软的JWT实现目前不支持加密(只支持签名).

                My understanding is that Microsoft's JWT implementation doesn't currently support encryption (only signing).

                这篇关于如何加密 JWT 安全令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何验证 JWT 令牌 下一篇:如何使用对称密钥配置 Microsoft JWT?

                相关文章

                最新文章

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

                <tfoot id='JN1Mk'></tfoot>

                1. <legend id='JN1Mk'><style id='JN1Mk'><dir id='JN1Mk'><q id='JN1Mk'></q></dir></style></legend>

                    • <bdo id='JN1Mk'></bdo><ul id='JN1Mk'></ul>

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