依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.7</version>
</dependency>
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import org.junit.jupiter.api.Test;
public class AesDemo {
private static final String KEY="baijuyi";
@Test
public void AesEncryption(){
String id="1";
byte[] key=KEY.getBytes();
AES aes = SecureUtil.aes(key);
String encryptHex = aes.encryptHex(id);
System.out.println(encryptHex);
}
@Test
public void AesDecrypt(){
byte[] key=KEY.getBytes();
AES aes = SecureUtil.aes(key);
String decryptStr = aes.decryptStr("xxxxxxxxxxxxxxxxxxx");
System.out.println(decryptStr);
}
}