1

I tried to decode a following base64 string in C#:

PGlmcmFtZSBzcmM9Imh0dHA6Ly9lbWJlZC5yZWR0dWJlLmNvbS8\/aWQ9Mzg1NjAmYmdjb2x
vcj0wMDAwMDAiIGZyYW1lYm9yZGVyPSIwIiB3aWR0aD0iNDM0IiBoZWlnaHQ9IjM0NCIgc2Nyb2xsaW5n
PSJubyIgYWxsb3dmdWxsc2NyZWVuPjwvaWZyYW1lPg==

But i'm getting an 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.

Even if i remove last

=

in the string above but still the same error.

Here is the code i use:

    byte[] decodedBytes = Convert.FromBase64String(embedCode);
    string decodedText = Encoding.UTF8.GetString(decodedBytes);

Why is that?

Thank you.

Mark Tr
  • 63
  • 1
  • 1
  • 8

1 Answers1

7

the correct Base64String is:

PGlmcmFtZSBzcmM9Imh0dHA6Ly9lbWJlZC5yZWR0dWJlLmNvbS8/aWQ9Mzg1NjAmYmdjb2x
vcj0wMDAwMDAiIGZyYW1lYm9yZGVyPSIwIiB3aWR0aD0iNDM0IiBoZWlnaHQ9IjM0NCIgc2Nyb2xsaW5n
PSJubyIgYWxsb3dmdWxsc2NyZWVuPjwvaWZyYW1lPg==

Well this is not a valid Base64String. Base64String can not have \ character. remove this character and it will work

Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171