Reputation: 19
I'm trying to write a byte array to file and then to read it again. The problem is that the byte array that I Read is different from that I wrote. The output of the code below is:
[B@21a06946 (Original byte array written)
[B@2fc14f68 (byte array read )
byte[] encryptedKey = rsaCipher.encrypt(AESKey, publicKeyPathName, transformation, encoding);
System.out.println(encryptedKey);
List<byte[]> list = new ArrayList<byte[]>();
list.add(encryptedKey);
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("encryptedKey"));
out.writeObject(list);
out.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream("encryptedKey"));
List<byte[]> byteList = (List<byte[]>) in.readObject();
in.close();
byte[] encryptedKey2 = byteList.get(0);
System.out.println(encryptedKey2);
Upvotes: 0
Views: 123
Reputation: 10285
Arrays do not have a proper String representation. To see the content, use the below instead
System.out.println(java.util.Arrays.toString(encryptedKey));
System.out.println(java.util.Arrays.toString(encryptedKey2));
Upvotes: 2