在Java中编码base64并在C#中解码 [英] Encoding base64 in Java and decoding in C#

查看:928
本文介绍了在Java中编码base64并在C#中解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在java和c#之间存在base64问题,将java编码字符串发送到一个java urlconnection的asp.net处理程序,我比较两个字符串,一个是从byte数组生成的,另一个是在asp中.net第一个解码并且都是相同的,但是在解码后,c#中的字节数组不等于java中的字节数组。
我使用新的sun.misc.BASE64Encoder()。encode(javabytearray);在java和System.Convert.FromBase64String(encodedstring);在dotnet。



from java:[0] [-24] [56] [1] [-56] [41] [-29] ........

to dotnet:[0] [232] [56] [1] [200] [41] [227] .........



类似的: Java中编码base64和解码在C#

我不能问上述问题,因为它是一个Q&A的网站,每当一个新的问题必须创建,不能在另一个问题内提出问题。

非常感谢


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

推荐答案

byte 在C#中未签名,并用Java签名。 Java 字节 -24 的位模式等于c# byte value 232 。所以你的代码应该是正确的。如果你想验证这一点,转换例如将$ 字节值转换为 int 并将 256 添加到负值。

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.

这篇关于在Java中编码base64并在C#中解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆