我必须以十六进制格式获得56字节的原始二进制文件的输出。 以下编码是我尝试过的,但输出错误。
这是我期待的输出:
0xd19f261efa71440103519930f483de39c4deffb333c35b89c88d505ad4203e98b0d1f34233dad8 2a4b9ba0a3531ede93203691a2b96fb45a
但我得到了不同的输出:
87168739A1D8972742F476D48F139348B06EDF38545BC3C00434DD5C464B2FDF8512EF75D05D897E A5523F8C1589AB5106A5CC986C859CBB
private byte[] encryptByTea(String info){
byte[] temp = info.getBytes();
int n = 8 - temp.length % 8;//Multiple if temp number less than 8, need to fill in the numbers
byte[] encryptStr = new byte[temp.length + n];
encryptStr[0] = (byte)n;
System.arraycopy(temp, 0, encryptStr, n, temp.length);
byte[] result = new byte[encryptStr.length];
for(int offset = 0; offset <result.length; offset += 8){
byte[] tempEncrpt = tea.encrypt(encryptStr, offset, KEY, 32);
System.arraycopy(tempEncrpt, 0, result, offset, 8);
}
return result;
}
//Through the TEA algorithm decryption information
private String decryptByTea(byte[] secretInfo){
byte[] decryptStr = null;
byte[] tempDecrypt = new byte[secretInfo.length];
for(int offset = 0; offset <secretInfo.length; offset += 8){
decryptStr = tea.decrypt(secretInfo, offset, KEY, 32);
System.arraycopy(decryptStr, 0, tempDecrypt, offset, 8);
}
int n = tempDecrypt[0];
return new String(tempDecrypt, n, decryptStr.length - n);
}