4

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?

Dave New
  • 38,496
  • 59
  • 215
  • 394
  • 1
    according to msdn: http://msdn.microsoft.com/en-us/library/system.convert.frombase64string(v=vs.71).aspx exception is thrown, when "The length of s, ignoring white space characters, is not an even multiple of 4.". But why it works on IIS Express... weird – wojtuch Jun 27 '13 at 09:11

1 Answers1

14

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.

Samuel Parkinson
  • 2,992
  • 1
  • 27
  • 38