简单的加密解密过程:执行第一次加密,执行第二次为解密还原
package xxx;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* 第一次加密,执行第二次解密
* @author hgg
* @version 2016年2月26日下午5:11:40
*/
public class 加密解密 {
public static void main(String[] args) throws IOException {
File file = new File("D:/tmp/test");
InputStream is = new FileInputStream(file);
writeToLocal("D:/tmp/test2",is);
}
/**
* 流写入本地文件
*
* @param destination
* @param input
* @throws IOException
*/
private static void writeToLocal(String destination, InputStream input)
throws IOException {
int index;
byte[] bytes = new byte[1024];
byte[] bytes2 = new byte[1024];
FileOutputStream downloadFile = new FileOutputStream(destination);
while ((index = input.read(bytes)) != -1) {
for (int i = 0; i<index;i++) {
//通过异或运算某个数字或字符串(这里以2为例)
bytes2[i] = (byte) (bytes[i]^2);
}
downloadFile.write(bytes2, 0, index);
downloadFile.flush();
}
downloadFile.close();
}
}
说明:(例子中,加密的字符为“2”)
1、执行第一次生成的为【加密】后的文件
2、将步骤1生成的文件再执行一次,生成的文件即为解密后的文件
然后你就发现可以把你的片,放进各大网盘了哈哈哈哈……罪过罪过