📄 desalgorithm.java
字号:
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
public class DESAlgorithm {
private static String algorithm = "DESede";
public static SecretKey genDESKey(byte[] keyByte) throws Exception {
SecretKey key = new SecretKeySpec(keyByte, algorithm);
return key;
}
public static byte[] desEncrypt(SecretKey key, String crypt)
throws Exception {
return desEncrypt(key, crypt.getBytes());
}
public static byte[] desEncrypt(SecretKey key, byte[] crypt)
throws Exception {
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.ENCRYPT_MODE, key);
return cipher.doFinal(crypt);
}
public static byte[] desDecrypt(SecretKey key, String crypt)
throws Exception {
return desDecrypt(key, crypt.getBytes());
}
public static byte[] desDecrypt(SecretKey key, byte[] crypt)
throws Exception {
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, key);
return cipher.doFinal(crypt);
}
public static String getAlgorithm() {
return algorithm;
}
public static void setAlgorithm(String algorithm) {
DESAlgorithm.algorithm = algorithm;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -