问题描述
java字节流加密图片,具体操作是单个字节异或一个数字,为什么加密后的图片无法打开
代码
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("haha.jpg");
fos = new FileOutputStream("hahasecret.jpg");
byte[] buffer = new byte[20];
int len;
while ((len = fis.read(buffer)) != -1) {
for (int i = 0; i < len; i++) {
buffer[i] = (byte) (buffer[i] ^ 1);
}
fos.write(buffer, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
结果
结果就是无法打开,不应该是可以打开但是里面的内容是乱的吗