title: How to generate JWT token signed with RS256 algorithm in C#
body: <p>I have a RSA Private key with me and I have to generate a JWT token using RS256 algorithm.
  I started with the below code which was working for &quot;HmacSha256&quot; algorithm
  but when i change it to RS256 it throws errors like &quot; IDX10634: Unable to create the SignatureProvider.Algorithm: 'System.String',SecurityKey:'Microsoft.IdentityModel.Tokens.SymmetricSecurityKey'&quot;</p>
  <p>After that I modified the code with RSACryptoServiceProvider() class. But i didnt get a solution.
  Please anyone can help with a sample code using  RSACryptoServiceProvider class with a private key.</p>
  <pre><code>public static string CreateToken()//Dictionary&lt;string, object&gt; payload
  {
      string key = GetConfiguration[&quot;privateKey&quot;].Tostring();
  
      var securityKey = 
          new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(
              Encoding.UTF8.GetBytes(key));
  
      var credentials = 
          new Microsoft.IdentityModel.Tokens.SigningCredentials(securityKey, &quot;RS256&quot;);
  
      var header = new JwtHeader(credentials);
  
      JwtPayload payload = new JwtPayload();
  
      payload.AddClaim(
          new System.Security.Claims.Claim(
              &quot;context&quot;, &quot;{'user': { 'name': 'username', 'email': 'email' }}&quot;, 
              JsonClaimValueTypes.Json));
      payload.AddClaim(new System.Security.Claims.Claim(&quot;iss&quot;, @&quot;app-key&quot;));
      payload.AddClaim(new System.Security.Claims.Claim(&quot;aud&quot;, &quot;meet.jitsi.com&quot;));
      payload.AddClaim(new System.Security.Claims.Claim(&quot;sub&quot;, &quot;meet.jitsi.com&quot;));
      payload.AddClaim(new System.Security.Claims.Claim(&quot;room&quot;, &quot;TestRoom&quot;));
  
      var secToken = new JwtSecurityToken(header, payload);
      var handler = new JwtSecurityTokenHandler();
  
      var tokenString = handler.WriteToken(secToken);
      return tokenString;
  }
  </code></pre>