利用Mybatis的TypeHandler实现字段加密
引言
记录使用Mybatis的TypeHandler实现对实体类字段的加密.
版本
-
Springboot2.5.3 -
MybatisPlus3.4.2 -
Mysql5.4.7
AES工具类
编写一个工具类,实现对数据的加解密操作.
public class AesUtils {
public static final String AES_MIDDLE_KEY = "chenZhiLing";
//aes的key
private static Key AES_KEY;
public static String encryptByAes(String content) {
if(ObjectUtils.isEmpty(content)){
return null;
}
try {
// 加密
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, getKey());
byte[] result = cipher.doFinal(content.getBytes());
return org.apache.commons.codec.binary.Base64.encodeBase64String(result);
} catch (Exception e)

本文介绍了如何在Springboot应用中,利用Mybatis的TypeHandler功能配合AES加密工具类,实现实体类字段的加密和解密操作,以及如何在实体类上添加注解进行自动处理。
最低0.47元/天 解锁文章
7124

被折叠的 条评论
为什么被折叠?



