开发者

Post data missing characters in base64

I am trying to send a post to my php script from a C# application but the base64_decode() keeps failing.

This is the string my post is trying to send:

stWC3F34AboxsfjbxAWtGU8WUHIombDMd6Z4WXxyOae0+NlISFHVEATxjE8EFKKMkDnQe0oFu8AvQM9lRaSSMgjYnyZvhXB8EiQDImgrsTmgvwsIeu4qZiW2O6cK4oaPUJIIFnEDlNCstc4s1mzseq0zv0xYPy3tRqbWPXVV9jv9BZiMFGxeVD+OKV/mO0NkVP4UVUMcFOXVCKh5HslVZv59lEqa5C230HSyv17/W0G1e7q4tBxWEhUwCfbldNtk

and when the script receives it the "+" are replaced with " " so i use str_replace() to readd them and then pass the output to base64_decode() but it keeps returning false.

This is the string that gets passed to base64_decode() BEFORE replacing the " " with "+"

stWC3F34AboxsfjbxAWtGU8WUHIombDMd6Z4WXxyOae0 NlISFHVEATxjE8EFKKMkDnQe0oFu8AvQM9lRaSSMgjYnyZvhXB8EiQDImgrsTmgvwsIeu4qZiW2O6cK4oaPUJIIFnEDlNCstc4s1mzseq0zv0xYPy3tRqbWPXVV9jv9BZiMFGxeVD OKV/mO0NkVP4UVUMcFOXVCKh5HslVZv59lEqa5C230HSyv17/W0G1e7q4tBxWEhUwCfbldNtk

This is the string that gets passed to base64_decode() AFTER replacing the " " with "+"

stWC3F34AboxsfjbxAWtGU8WUHIombDMd6Z4WXxyOae0+NlISFHVEATxjE8EFKKMkDnQe0oFu8AvQM9lRaSSMgjYnyZvhXB8EiQDImgrsTmgvwsIeu4qZiW2O6cK4oaPUJIIFnEDlNCstc4s1mzseq0zv0xYPy3tRqbWPXVV9jv9BZiMFGxeVD+OKV/mO0NkVP4UVUMcFOXVCKh5HslVZv59lEqa5C230HSyv17/W0G1e7q4tBxWEhUwCfbldNtk

And from what I read the only reason why it should return false is if the string contains characters from outside the base64 alphabet, but it appears to be a valid base64 string.

Any help is appreciated. If I can't get this fixed I'll just start posting hex strings inst开发者_如何学运维ead of base64.


Are you doing a URLEncode on the string before you send it? That should fix the problem with the plus sign.


You also need to replace any slash characters (/), which represents the value 63 in standard base64 encoding. The common usage is to convert + to -, and / to _.

See http://en.wikipedia.org/wiki/Base64#URL_applications

In addition, some base64 decoders require that the string be padded with = characters so that the string's length is a multiple of 3. I don't know if PHP's base64_decode requires this. See the linked Wikipedia article for information about the padding.


Try using urlencode in php and HttpServerUtility.UrlDecode in C#

EDIT: Sorry, what you want is the other way round:

HttpServerUtility.UrlEncode in c# and urldecode in php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜