我基本上将这里的代码http://www.avajava.com/tutorials/lessons/how-do-i-encrypt-and-decrypt-files-using-des.html用于加密应用程序,但我希望能够选择操作模式,所以我添加了这个:
private String key;
private static String algorithmMode;
public DESCrypt(String password, String algorithmMode) {
this.key = password;
this.algorithmMode = "DES/" + algorithmMode + "/PKCS5Padding";
}
主要看起来像这样:
public static void main(String[] args) {
try {
DESCrypt des = new DESCrypt("12345678", algorithmMode);
// FileInputStream fis1 = new FileInputStream("d:\\_test.txt");
// FileOutputStream fos1 = new FileOutputStream("d:\\_test.txt.des");
// des.encrypt(fis1, fos1);
FileInputStream fis = new FileInputStream("d:\\_test.txt.des");
FileOutputStream fos = new FileOutputStream("d:\\_test.txt");
des.decrypt(fis, fos);
} catch (Exception e) {
e.printStackTrace();
}
}
正如我在标题中所说,它适用于欧洲央行,但在其他模式下我只能加密。