您的位置:首页 > 编程语言 > Java开发

java实现的加密解密

2016-04-11 11:25 435 查看
void encode(File enfile, File defile) throws Exception {
String Algorithm = "DES";
byte[] key = "cnmmlgb!".getBytes();
SecretKey deskey = new SecretKeySpec(key, Algorithm);
Cipher c = Cipher.getInstance(Algorithm);
//c.init(Cipher.ENCRYPT_MODE, deskey);//加密模式
c.init(Cipher.DECRYPT_MODE, deskey);//解密模式
byte[] buffer = new byte[100 * 1024];
FileInputStream in = new FileInputStream(enfile);
OutputStream out = new FileOutputStream(defile);
CipherInputStream cin = new CipherInputStream(in, c);
int i;
while ((i = cin.read(buffer)) != -1) {
out.write(buffer, 0, i);
}
out.close();
cin.close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: