代码
package com.my.test.utils;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import lombok.experimental.UtilityClass;
import java.nio.charset.StandardCharsets;
@UtilityClass
public class AesUtil {
private static String KEY="CCAc1^ou%VL5ovgc";
private static SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES,KEY.getBytes(StandardCharsets.UTF_8));
public static String encryptHex(String str){
return aes.encryptHex(str);
}
public static String decryptStr(String str){
return aes.decryptStr(str, CharsetUtil.CHARSET_UTF_8);
}
}
使用效果
package com.my.test.utils;
public class TTT {
public static void main(String[] args) {
String aaaa = AesUtil.encryptHex("AAAA");
System.out.println(aaaa);
System.out.println(AesUtil.decryptStr(aaaa));
}
}
结果:
a619c5a730bdf5e9579e6722ecf88356
AAAA