Base64编码解码给出不同的结果

Base64编码解码给出不同的结果

问题描述:

我工作的一个小项目通过StreamServe(google一下:P),在那里我得到一些Base64编码的连接codeD的内容。我试图脱code中的字符串的base64多去codeRS都将返回正确的结果..除了通过StreamServe的Base64De codeString的方法。

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.

带连接codeD字符串是:VABlAHMAdABpAG4AZwAgAGIAYQBzAGUANgA0AA =='预期的结果是:测试的base64

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

不过内通过StreamServe结果是:TSIG AE4

However within Streamserve the result is: 'Tsig ae4'

它只是跳过其他字母。现在,我知道大多数人不知道通过StreamServe,但我有一种预感,这可能是一个字符编码的问题..问题,并希望有人有什么线索可能会被这里发生的一切。

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.

我可以毫无问题的连接通过StreamServe内code /德code字符串..只是不是字符串,我得到的输入

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

的问题是,你在UTF-16和解码编码回ASCII或UTF8。编码字符串为base64之前更改您的字符串编码为UTF8,它应该工作正常。

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.

下面是BASE64 blob的十六进制转储:

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

这相当于以下ASCII文本:

Which translates to the following ASCII text:

Testing base64