加密:
//加密
public void test() throws Exception {
File file = new File("D:\\zsc\\ccc.mp4");
FileInputStream fis = new FileInputStream(file);
File files = new File("D:\\zsc\\aaa.mp4");
FileOutputStream fos = new FileOutputStream(files);
byte by[] = new byte[1024];
long count = file.length()%1024 == 0 ? file.length()/1024 : file.length()/1024 + 1;
for (int i = 0; i < count; i++) {
fis.read(by);
if (i == count-1) {
for (int j=0;j<file.length()%1024;j++){
by[j] = (byte) (by[j] +5);
}
} else {
for (int j = 0; j < by.length; j++) {
by[j] = (byte) (by[j] + 5);
}
}
fos.write(by);
}
fos.close();
fis.close();
}
解密:
//解密
public void test() throws Exception {
File file = new File("D:\\zsc\\aaa.mp4");
FileInputStream fis = new FileInputStream(file);
File files = new File("D:\\zsc\\eee.mp4");
FileOutputStream fos = new FileOutputStream(files);
byte by[] = new byte[1024];
long count = file.length()%1024 == 0 ? file.length()/1024 : file.length()/1024 + 1;
for (int i = 0; i < count; i++) {
fis.read(by);
for (int j = 0; j < by.length; j++) {
by[j] = (byte) (by[j] - 5);
}
fos.write(by);
}
fos.close();
fis.close();
}