Stack Exchange
The input is not a valid Base-64 string how to solve
I have the following code:
var test = "eyJhbGciOiJSUzI1NiIsImtpZCI6IlRlc3RDZXJ0IiwidHlwIjoiYXQrand0In0";
var base64EncodedBytes = System.Convert.FromBase64String(test);
var hidenString = System.Text.Encoding.UTF8.GetString(base64EncodedBytes);

and I get the following error: 'The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.'
Any help? how do I decode this?
I went to this website https://www.base64decode.org/ and decode the string, so the string can be decoded.
I would expect my code to work, the string produced by the website was {"alg":"RS256","kid":"TestCert","typ":"at+jwt"}

It misses "=" character at the end as it does not have the proper length. as is is a 3byte -> 4byte encoding length must be dividable by 4 and your string only has 63 characters. There are some variants of base64 where you can omit the padding but not in the Net implementation.

As this looks like a Jwt Token you might rather look up the documentation surrounding what the frameworks already provides for those tokens so there is no need to decode base64 in the first place. JwtSecurityToken(Handler) might be a good start for reading.

Instead of break your JWT token and decode it by yourself ... take a look here how to decode JWT token in a nice way

I did a rollback of your last edit. The answer should not be posted in the question. And in this case, it was also misleading. so I guess that after splitting in 3 parts I should add the = - this is the wrong conclusion. It's not simply adding a '=' and everything is fine. A Base64 string can have 0, 1 or 2 padding characters ('=') on the end, depending on the length. Aside from that,  JWT uses Base64URL which also has a slightly different character set. Unfortunately, the accepted answer doesn't mention any of this.

Generally, I absolutely support the idea of letting a tested library do the work. However, if you really want to do it manually or want to understand the background of why the decoding failed, you might want to read the answers in this Q/A (one answer from me): Could not decode JWT payload from base64

If you encode properly, your base64 should look like this:
eyJhbGciOiJSUzI1NiIsImtpZCI6IlRlc3RDZXJ0IiwidHlwIjoiYXQrand0In0=

Notice the padding with a = in the end. You need to fix your base64 string, wherever it came from. The FromBase64String method is correct in complaining.
