DES_cách 3
DES_cách 3
ActionEvent evt) {
// TODO add your handling code here:
try{
String key = txtk.getText();
FileInputStream fis = new FileInputStream("D:\\TH_BMTT\\DESCS\\
Des.txt");
FileOutputStream fos = new FileOutputStream("D:\\TH_BMTT\\DESCS\\
EnDes.txt");
encrypt(key, fis, fos);
JOptionPane.showMessageDialog(null, "Đã mã hóa văn bản");
BufferedReader br = null;
String fileName ="D:\\TH_BMTT\\DESCS\\EnDes.txt";
br = new BufferedReader(new FileReader(fileName));
StringBuffer sb = new StringBuffer();
char[] ca = new char[5];
while(br.ready()){
int len = br.read(ca);
sb.append(ca, 0, len);
}
br.close();
System.out.println("Du Lieu la:" + " " + sb);
String chuoi = sb.toString();
txtc.setText(chuoi);
}catch(Throwable e){
e.printStackTrace();
}
private static void decrypt(String key, InputStream is, OutputStream os) throws
Throwable{
encryptOrDecrypt(key, Cipher.DECRYPT_MODE, is, os);
}
if(mode==Cipher.ENCRYPT_MODE){
cipher.init(Cipher.ENCRYPT_MODE, desKey);
CipherInputStream cis = new CipherInputStream(is, cipher);
doCopy(cis, os);
}else if(mode==Cipher.DECRYPT_MODE){
cipher.init(Cipher.DECRYPT_MODE, desKey);
CipherOutputStream cos = new CipherOutputStream(os, cipher);
doCopy(is, cos);
}
}