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

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

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

      1. <tfoot id='h87h2'></tfoot>

        JWT 错误 IDX10634:无法创建 SignatureProvider C#

        时间:2023-06-03

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

                <tbody id='PL1TX'></tbody>
                <bdo id='PL1TX'></bdo><ul id='PL1TX'></ul>

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

                1. 本文介绍了JWT 错误 IDX10634:无法创建 SignatureProvider C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试运行我的应用,但遇到以下错误:

                  I'm trying to run my app but it get stuck with the following error:

                  System.NotSupportedException HResult=0x80131515 消息=IDX10634:无法创建 SignatureProvider.算法:'[PII 被隐藏默认.将 IdentityModelEventSource.cs 中的ShowPII"标志设置为 true显示它.]', SecurityKey: '[PII 默认隐藏.设置IdentityModelEventSource.cs 中的ShowPII"标志为 true 以显示它.]'不支持.

                  System.NotSupportedException HResult=0x80131515 Message=IDX10634: Unable to create the SignatureProvider. Algorithm: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]', SecurityKey: '[PII is hidden by default. Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]' is not supported.

                  在哪里

                  算法是RS256

                  卡在执行这条指令:var sectoken = tokenHandler.CreateToken(tokenDescriptor);

                  这是什么意思?我的代码出了什么问题?我该如何解决这个问题?

                  What does it mean? What went wrong in my code? How can I solve this?

                  这是我的代码:

                  using System.Security.Claims;
                  using System.Text;
                  using System.Threading.Tasks;
                  //...
                  public class TokenManager
                  {
                      private string unencoded_key = "CaptainDeadpool";
                      private string encoded_key = "CaptainDeadpool";
                  //...
                      public TokenManager()
                      {
                          var plainTextBytes = Encoding.UTF8.GetBytes(unencoded_key);
                          encoded_key = Convert.ToBase64String(plainTextBytes);
                      }
                  
                  
                      public string CreateFromUsername(string usr, int? timer)
                      {
                          if (timer == null) {  timer = 30; }
                          double timeadd = Convert.ToDouble(timer);
                  
                          var secret = Convert.FromBase64String(encoded_key);
                          var tokenHandler = new JwtSecurityTokenHandler();
                  
                          var actual = DateTime.UtcNow;
                  
                          var tokenDescriptor = new SecurityTokenDescriptor
                          {
                              Subject = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, usr) }),
                              Expires = actual.AddMinutes(timeadd),
                  
                              SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(secret), SecurityAlgorithms.RsaSha256Signature)
                          };
                  
                          var sectoken = tokenHandler.CreateToken(tokenDescriptor);
                          var stringtoken = tokenHandler.WriteToken(sectoken);
                  
                          return stringtoken;
                      }
                  //...
                  

                  这是我发出错误时的 tokenDescriptor 的内容:

                  Here's my tokenDescriptor's content while issuing the error:

                  推荐答案

                  不知道该错误消息是什么意思,但我认为没关系,因为您的代码在逻辑上是错误的.RSA 是非对称算法,但您正在尝试将 SymmetricSecurityKey 与它一起使用.

                  No idea what that error message means, but it doesn't matter I think, because your code is logically wrong. RSA is assymetric algorithm, but you are trying to use SymmetricSecurityKey with it.

                  所以要么使用另一种(对称)签名算法(并确保您的密钥大小对此算法有效),例如:

                  So either use another (symmetric) signature algorithm (and ensure that your key size is valid for this algorithm), for example:

                  // adjust key size
                  private string unencoded_key = "CaptainDeadpool!";
                  private string encoded_key = "CaptainDeadpool!";
                  // ...
                  SigningCredentials = new SigningCredentials(
                      new SymmetricSecurityKey(secret), 
                      SecurityAlgorithms.HmacSha256Signature)
                  

                  或者提供有效的密钥,例如:

                  Or provide valid key, for example:

                  private readonly RSA _rsa;
                  public TokenManager() {
                      // import instead of creating new, if necessary
                      _rsa = new RSACryptoServiceProvider(2048);            
                  }
                  // ...
                  
                  SigningCredentials = new SigningCredentials(
                      new RsaSecurityKey(_rsa), 
                      SecurityAlgorithms.RsaSha256Signature)
                  

                  这篇关于JWT 错误 IDX10634:无法创建 SignatureProvider C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 x509 证书签署 JWT 令牌时遇到问题 下一篇:在 C# 中正确使用 JwtTokens

                  相关文章

                  最新文章

                2. <i id='XvqMh'><tr id='XvqMh'><dt id='XvqMh'><q id='XvqMh'><span id='XvqMh'><b id='XvqMh'><form id='XvqMh'><ins id='XvqMh'></ins><ul id='XvqMh'></ul><sub id='XvqMh'></sub></form><legend id='XvqMh'></legend><bdo id='XvqMh'><pre id='XvqMh'><center id='XvqMh'></center></pre></bdo></b><th id='XvqMh'></th></span></q></dt></tr></i><div id='XvqMh'><tfoot id='XvqMh'></tfoot><dl id='XvqMh'><fieldset id='XvqMh'></fieldset></dl></div>
                    <bdo id='XvqMh'></bdo><ul id='XvqMh'></ul>
                3. <legend id='XvqMh'><style id='XvqMh'><dir id='XvqMh'><q id='XvqMh'></q></dir></style></legend>
                4. <small id='XvqMh'></small><noframes id='XvqMh'>

                  <tfoot id='XvqMh'></tfoot>