import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public void setProvider() {
java.security.Security.addProvider(new com.sun.crypto.provider.SunJCE());
}
public void encryptFile(String originalFile, String encryptedFile, String password) throws Exception {
CipherOutputStream out;
InputStream in;
Cipher cipher;
SecretKey key;
byte[] byteBuffer;
cipher = Cipher.getInstance("DES");
key = new SecretKeySpec(password.getBytes(), "DES");
cipher.init(Cipher.ENCRYPT_MODE, key);
in = new FileInputStream(originalFile);
out = new CipherOutputStream(new FileOutputStream(encryptedFile), cipher);
byteBuffer = new byte[1024];
for (int n;(n = in.read(byteBuffer)) != -1;out.write(byteBuffer, 0, n));
in.close();
out.close();
//new File(originalFile).delete();
}
public void decryptFile(String encryptedFile, String decryptedFile, String password) throws Exception {
CipherInputStream in;
OutputStream out;
Cipher cipher;
SecretKey key;
byte[] byteBuffer;
cipher = Cipher.getInstance("DES");
key = new SecretKeySpec(password.getBytes(), "DES");
cipher.init(Cipher.DECRYPT_MODE, key);
in = new CipherInputStream(new FileInputStream(encryptedFile), cipher);
out = new FileOutputStream(decryptedFile);
byteBuffer = new byte[1024];
for (int n;(n = in.read(byteBuffer)) != -1;out.write(byteBuffer, 0, n));
in.close();
out.close();
//new File(encryptedFile).delete();
}