68 lines
2.1 KiB
Java
68 lines
2.1 KiB
Java
//
|
|
// Source code recreated from a .class file by IntelliJ IDEA
|
|
// (powered by FernFlower decompiler)
|
|
//
|
|
|
|
package org.example;
|
|
|
|
import javax.crypto.Cipher;
|
|
import javax.crypto.SecretKey;
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
import java.nio.charset.Charset;
|
|
import java.util.Base64;
|
|
|
|
public class SecurityUtil {
|
|
private static final String ALGORITHM_3DES = "DESede";
|
|
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
|
|
|
public SecurityUtil() {
|
|
}
|
|
|
|
public static byte[] encrypt3DES(String encryptPassword, byte[] encryptByte) {
|
|
try {
|
|
Cipher cipher = init3DES(encryptPassword, 1);
|
|
byte[] doFinal = cipher.doFinal(encryptByte);
|
|
return doFinal;
|
|
} catch (Exception var4) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static String encrypt3DES(String encryptPassword, String encryptStr) {
|
|
try {
|
|
Cipher cipher = init3DES(encryptPassword, 1);
|
|
byte[] enBytes = cipher.doFinal(encryptStr.getBytes(DEFAULT_CHARSET));
|
|
return Base64.getEncoder().encodeToString(enBytes);
|
|
} catch (Exception var4) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static byte[] decrypt3DES(String decryptPassword, byte[] decryptByte) {
|
|
try {
|
|
Cipher cipher = init3DES(decryptPassword, 2);
|
|
byte[] doFinal = cipher.doFinal(decryptByte);
|
|
return doFinal;
|
|
} catch (Exception var4) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static String decrypt3DES(String decryptPassword, String decryptString) {
|
|
try {
|
|
Cipher cipher = init3DES(decryptPassword, 2);
|
|
byte[] deBytes = cipher.doFinal(Base64.getDecoder().decode(decryptString));
|
|
return new String(deBytes, DEFAULT_CHARSET);
|
|
} catch (Exception var4) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static Cipher init3DES(String decryptPassword, int cipherMode) throws Exception {
|
|
SecretKey deskey = new SecretKeySpec(decryptPassword.getBytes(), "DESede");
|
|
Cipher cipher = Cipher.getInstance("DESede");
|
|
cipher.init(cipherMode, deskey);
|
|
return cipher;
|
|
}
|
|
}
|