title: Create a valid JWT Token for DocuSign API
body: <p>Ι try to create a valid jwt token</p>
  <p>From settings i create an RSA keypairs and i get the private key without the &quot;-----BEGIN RSA PRIVATE KEY----------END RSA PRIVATE KEY-----
  &quot;</p>
  <pre><code>var rsaPrivateKey = @&quot;MIIEogIBAAKCAQEAoGujdXbYVy68a4CSWz963SpYxVs20/..............HQ/jW8pFom6gJreCDkca5axYo/gXp3W3rQHFTkooTNbOk2MyFMZUqRD3aCG1wuUW3w8TgGX4slrLDV0pP4=&quot;;
  
  var jwt = Sign(rsaPrivateKey);
  </code></pre>
  <p>I follow the instructions here <a href="https://developers.docusign.com/docs/admin-api/admin101/application-auth/" rel="nofollow noreferrer">https://developers.docusign.com/docs/admin-api/admin101/application-auth/</a> and after a lot of hours i create this method</p>
  <pre><code>    public string Sign(string privateKey)
      {
          List&lt;string&gt; segments = new List&lt;string&gt;();
  
          var header = new { alg = &quot;RS256&quot;, typ = &quot;JWT&quot; };
  
          //For production environments, use account.docusign.com
          var payload = new
          {
              iss = &quot;4f489d61-dc8b------a828-3992e670dcbc&quot;,
              iat = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds,
              aud = &quot;account-d.docusign.com&quot;,
              scope = &quot;signature impersonation&quot;
          };
  
          byte[] headerBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(header, Formatting.None));
          byte[] payloadBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload, Formatting.None));
  
          segments.Add(Base64UrlEncode(headerBytes));
          segments.Add(Base64UrlEncode(payloadBytes));
  
          string stringToSign = string.Join(&quot;.&quot;, segments.ToArray());
  
          byte[] bytesToSign = Encoding.UTF8.GetBytes(stringToSign);
  
          byte[] keyBytes = Convert.FromBase64String(privateKey);
  
          var privKeyObj = Asn1Object.FromByteArray(keyBytes);
          var privStruct = RsaPrivateKeyStructure.GetInstance((Asn1Sequence)privKeyObj);
  
          ISigner sig = SignerUtilities.GetSigner(&quot;SHA256withRSA&quot;);
  
          sig.Init(true, new RsaKeyParameters(true, privStruct.Modulus, privStruct.PrivateExponent));
  
          sig.BlockUpdate(bytesToSign, 0, bytesToSign.Length);
          byte[] signature = sig.GenerateSignature();
  
          segments.Add(Base64UrlEncode(signature));
          return string.Join(&quot;.&quot;, segments.ToArray());
      }
  
      private static string Base64UrlEncode(byte[] input)
      {
          var output = Convert.ToBase64String(input);
          output = output.Split('=')[0]; // Remove any trailing '='s
          output = output.Replace('+', '-'); // 62nd char of encoding
          output = output.Replace('/', '_'); // 63rd char of encoding
          return output;
      }
  </code></pre>
  <p>When i check the JWT validation in this tool <a href="https://jwt.io/#debugger-io" rel="nofollow noreferrer">https://jwt.io/#debugger-io</a>, i get invalid signature error.</p>
  <p>How can i fix the token  ?? I cant proceed with Step 2 Obtain the access token...</p>