我希望将TEA加密的结果(一个byte[]数组)转换为字符串,然后再将其转换回byte[]数组,并获取相同的byte[]数组。
//Encryption in the sending side
String stringToEncrypt = "blablabla"
byte[] encryptedDataSent = tea.encrypt(stringToEncrypt.getBytes());
String dataToSend = new BigInteger(encryptedDataSent).toString());
//Decryption side in the reception side
byte[] encryptedDataReceived = new BigInteger(dataToSend).toByteArray();
然而,当我尝试这样做时:
System.out.println(new String(encryptedDataSent));
System.out.println(new String(encryptedDataReceived));
boolean equality = Arrays.equals(encryptedDataReceived,encryptedDataSent);
System.out.println("Are two byte arrays equal ? : " + equality);
输出结果为:
所以,当我们打印它们时,这两个byte[]看起来是相同的,但实际上它们并不完全相同,因为我们看到了“false”,这对于我之后的解密工作是一个问题。&h�7�"�PAtj݄�I��Z`H-jK�����f
&h�7�"�PAtj݄�I��Z`H-jK�����f
两个byte数组相等吗?:false
我还尝试发送一个
String with new String(byte[])
,但在将其转换回byte[]时,它具有相同的问题。我希望一开始和转换后的byte[]完全相同。
您是否有解决方案或了解我在转换中做错了什么?