[英]Encoding base64 in Java and decoding in C#
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 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解码 c# 中的字节数组与 java 中的字节数组不相等。 Im using new sun.misc.BASE64Encoder().encode(javabytearray);我正在使用新的 sun.misc.BASE64Encoder().encode(javabytearray); in java and System.Convert.FromBase64String(encodedstring);在 java 和 System.Convert.FromBase64String(encodedstring) 中; in dotnet.在点网中。
from java: "[0] [-24] [56] [1] [-56] [41] [-29]........."来自 java:“[0] [-24] [56] [1] [-56] [41] [-29]......”
to dotnet: "[0] [232] [56] [1] [200] [41] [227]........."到 dotnet:“[0] [232] [56] [1] [200] [41] [227]......”
Similar: Encoding base64 in Java and decoding in C#类似: 在 Java 中编码 base64 并在 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多谢
byte
is unsigned in C# and signed in Java. byte
在 C# 中未签名,在 Java 中签名。 The bit pattern of the Java byte
value -24
is equal to the bit pattern of the c# byte
value 232
. Java byte
值-24
的位模式等于 c# byte
值232
的位模式。 So your code should be correct.所以你的代码应该是正确的。 If you want to verify this, convert eg the Java byte
values to int
and add 256
to the negative values.如果您想验证这一点,请将 Java byte
值转换为int
并将256
添加到负值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.