encodingcharacter-encodingbase64

Base64 decoding gives different result


I'm working on a little Streamserve project (google it :P) where I get some Base64 encoded content. I've tried to decode the base64 string with multiple decoders and all return the correct result.. except the Base64DecodeString method in Streamserve.

The encoded string is: 'VABlAHMAdABpAG4AZwAgAGIAYQBzAGUANgA0AA==' The expected result is: 'Testing base64'

However within Streamserve the result is: 'Tsig ae4'

It simply skips every other letter. Now I know most people dont know Streamserve, but I have a hunch that this might be a character encoding problem.. problem and was hoping someone has a clue what might be happening here.

I can without any problem encode/decode strings within streamserve.. just not strings I get as input


Solution

  • The issue is that you're encoding in UTF-16 and decoding back to ASCII or UTF8. Change your string encoding to UTF8 before encoding the string to base64 and it should work fine.

    Here's the hex dump of that base64 blob:

    54 00 65 00 73 00 74 00 69 00 6e 00 67 00 20 00 62 00 61 00 73 00 65 00 36 00 34 00
    

    If you remove the null bytes, you get this:

    54 65 73 74 69 6e 67 20 62 61 73 65 36 34
    

    Which translates to the following ASCII text:

    Testing base64