Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert.FromBase64String(...) throws a FormatException

The following line of code runs fine in IIS Express:

Convert.FromBase64String("dmVoaWNsZUlkPTE0MTM=??");

But when run on my local IIS 8 server, it throws the following exception:

System.FormatException: 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.

Why is this happening?

like image 552
Dave New Avatar asked Nov 14 '25 09:11

Dave New


1 Answers

The last two characters "??" are not valid in a base 64 string.

Have a read here: https://en.wikipedia.org/wiki/Base64

The string should end in an alphanumeric character or be padded with one or more = characters.

Edit — Decoding the string without the ? characters returns "vehicleId=1413", so I guess it's just a case of removing them.

like image 155
Samuel Parkinson Avatar answered Nov 17 '25 05:11

Samuel Parkinson