desjava代码 java示例代码( 四 )


}
//取得要解密的文件并解密
File file = new File(source);
String filename = file.getName();
try {
//输出流,请注意文件名称的获取
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dest));
//输入流
CipherInputStream in = new CipherInputStream(new BufferedInputStream(
new FileInputStream(file)), cipher);
int thebyte = 0;
while ( (thebyte = in.read()) != -1) {
out.write(thebyte);
}
in.close();
out.close();
}
catch (Exception ey5) {
throw new RuntimeException(ey5);
}
}
public static void encrypt(String keyPath, String source, String dest) {
SecretKey key = null;
try
{
ObjectInputStream keyFile = new ObjectInputStream(
//读取加密密钥
new FileInputStream(keyPath));
key = (SecretKey) keyFile.readObject();
keyFile.close();
}
catch (FileNotFoundException ey1) {
throw new RuntimeException(ey1);
}
catch (Exception ey2) {
throw new RuntimeException(ey2);
}
//用key产生Cipher
Cipher cipher = null;
try {
//设置算法,应该与加密时的设置一样
cipher = Cipher.getInstance("DES");
//设置解密模式
cipher.init(Cipher.ENCRYPT_MODE, key);
}
catch (Exception ey3) {
throw new RuntimeException(ey3);
}
//取得要解密的文件并解密
File file = new File(source);
String filename = file.getName();
try {
//输出流,请注意文件名称的获取
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(dest));
//输入流
CipherInputStream in = new CipherInputStream(new BufferedInputStream(
new FileInputStream(file)), cipher);
int thebyte = 0;
while ( (thebyte = in.read()) != -1) {
out.write(thebyte);
}
in.close();
out.close();
}
catch (Exception ey5) {
throw new RuntimeException(ey5);
}
}
}
【desjava代码 java示例代码】desjava代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java示例代码、desjava代码的信息别忘了在本站进行查找喔 。

推荐阅读