title: Could not decode JWT payload from base64
body: <p>I'm going to decode a JWT token from request header, it looks like this:</p>
  
  <blockquote>
    <p>eyJzdWIiOiIxIiwiZXZlbnRfaWQiOiI3ZTA3Y2JmNC0wYjYyLTQ1MzMtYmE5ZC1mZGFjNDkyNTNjZTUiLCJpYXQiOiIxNTkwODk4Mzg1IiwiZXhwIjoiMTU5MDkwMTk4NSIsImlzcyI6ImxvY2FsaG9zdDo0NDM4NyIsInRpbWV6b25lX29mZnNldCI6LTcsInVzciI6Im1pbmcuaGlldS4xMzEyIiwiYWxpYXMiOiJNaW5nIEhpZXUiLCJwaG9uZSI6IjA4NDQ1OTAyNTIiLCJlbWFpbCI6ImhpZXVhbWlAZ21haWwuY29tIn0</p>
  </blockquote>
  
  <pre><code>public static string Base64Decode(string base64EncodedData)
  {
      var base64EncodedBytes = Convert.FromBase64String(base64EncodedData);
      return Encoding.UTF8.GetString(base64EncodedBytes);
  }
  </code></pre>
  
  <p>When passing the token above to decode method, it throws an exception that tells:</p>
  
  <blockquote>
    <p>Invalid length for a Base-64 char array or string</p>
  </blockquote>
  
  <p>dotnetfiddle referrence: <a href="https://dotnetfiddle.net/Z2TUz9" rel="nofollow noreferrer">https://dotnetfiddle.net/Z2TUz9</a></p>
  
  <p>But when using it in javascript (using atob function), it works properly.</p>
  
  <p>Could anyone tell me why, then tell me how can I decode it in C#?</p>