Im having problems whith base64 between java and c#, im sending encoded string to a asp.net handler from an java urlconnection, i compare both strings, the one generated in java from byte array and the one received in asp.net first decoding and both are identical but after decode the byte array in c# arent equal from byte array in java.
Im using new sun.misc.BASE64Encoder().encode(javabytearray); in java and System.Convert.FromBase64String(encodedstring); in dotnet.
from java: "[0] [-24] [56] [1] [-56] [41] [-29] ........."
to dotnet: "[0] [232] [56] [1] [200] [41] [227] ........."
Similar: Encoding base64 in Java and decoding in C#
i cant ask it in question above because it is an Q&A site and every time an new question must be created, cant ask an question inside another question.
thanks a lot
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
byte
is unsigned in C# and signed in Java. The bit pattern of the Java byte
value -24
is equal to the bit pattern of the c# byte
value 232
. So your code should be correct. If you want to verify this, convert e.g. the Java byte
values to int
and add 256
to the negative values.