我试图在Java作为客户端和C作为服务器之间发送一些加密的整数,使用对称密钥,这里是代码.... 问题是我无法读取数字或整数!!!! 我在Java端使用writeInt函数首先发送数字位以在循环中使用它来分别加密/解密每个数字,然后我使用对称密钥来加密/解密整个数字。 知道如何让它发挥作用吗?
这是java代码:
ls -1 file* | xargs -I '{}' bash -c "attr -g some.attr '{}' | tr '\n' ' ' ; echo" | sort -n -t ':' -k2,2
Attribute "some.attr" had a 1 byte value for file3: 1
Attribute "some.attr" had a 1 byte value for file1: 2
Attribute "some.attr" had a 1 byte value for file2: 3
这是C方:
public void sendData(int data) throws IOException
{
int dataInInt = data, numberOfDigits = 0;
System.out.println("DATAININT = " + dataInInt);
while(dataInInt != 0)
{
dataInInt /= 10;
numberOfDigits++;
}
dataInInt = data;
System.out.println("Number of digits to be sent = " + numberOfDigits);
dout.writeInt(numberOfDigits);
int [] dataInDigits = new int [numberOfDigits];
for (int j = (numberOfDigits - 1); j >= 0; j--)
{
dataInDigits[j] = dataInInt % 10;
dataInInt /= 10;
}
int [] dataToSendInt = new int [numberOfDigits];
for (int i = 0; i < dataToSendInt.length; i++)
{
dataToSendInt[i] = dataInDigits[i] ^ symmetricKeyInDigits[i % symmetricKeyInDigits.length];
System.out.println("TOSEND = " + dataToSendInt[i]);
dout.writeInt(dataToSendInt[i]);
}
}
答案 0 :(得分:0)
而不是将它们作为整数发送并使用writeInt,而是将整数作为字符串发送并在任一侧转换它们。还使用printWriter。