org.yes.tools.utils.AESUtil Maven / Gradle / Ivy
package org.yes.tools.utils;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;
import org.springframework.stereotype.Component;
import org.yes.tools.core.properties.AESProperties;
import java.nio.charset.StandardCharsets;
/**
* AES 工具类
*
* @author Co.
* @date 2022年 07月15日 15:39:10
*/
@Component
public class AESUtil {
/***
* 加密
*
* @author Co.
* @date: 2022/7/15 16:12
* @return
*/
public static String encryption(String data) {
AES SECRET_AES = new AES(Mode.CBC, Padding.PKCS5Padding,
AESProperties.KEY.getBytes(StandardCharsets.UTF_8),
AESProperties.IV.getBytes(StandardCharsets.UTF_8)
);
String encryptHex = SECRET_AES.encryptHex(data, StandardCharsets.UTF_8);
return encryptHex;
}
/***
* 解密
*
* @author Co.
* @date: 2022/7/15 16:12
* @return
*/
public static String decrypt(String data) {
AES SECRET_AES = new AES(Mode.CBC, Padding.PKCS5Padding,
AESProperties.KEY.getBytes(StandardCharsets.UTF_8),
AESProperties.IV.getBytes(StandardCharsets.UTF_8)
);
String decryptStr = SECRET_AES.decryptStr(data, StandardCharsets.UTF_8);
return decryptStr;
}
}