Dave New
Dave New

Reputation: 40092

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?

Upvotes: 4

Views: 24053

Answers (1)

Samuel Parkinson
Samuel Parkinson

Reputation: 3100

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.

Upvotes: 14

Related Questions