标签:ISE 集成 div import 简单 解密 salt alt group
jasypt是一个简单方便的第三方加解密库,可以快速的集成到springboot环境中
<!-- 数据库加密 --> <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>3.0.2</version> </dependency> <!-- SM4 --> <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcpkix-jdk15on</artifactId> <version>1.60</version> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.5.9</version> </dependency>
import org.jasypt.encryption.StringEncryptor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import cn.hutool.core.util.CharsetUtil; import cn.hutool.crypto.SmUtil; import cn.hutool.crypto.symmetric.SymmetricCrypto; /** * jasypt 自定义数据库密码加密器 - SM4加密算法 * * @author jiaqiankun */ @Component("customStringEncryptor") public class CustomStringEncryptor implements StringEncryptor { @Value("${jasypt.encryptor.salt}") private String salt; @Override public String encrypt(String message) { SymmetricCrypto sm4 = SmUtil.sm4(salt.getBytes()); String encryptHex = sm4.encryptHex(message); return encryptHex; } @Override public String decrypt(String encryptedMessage) { SymmetricCrypto sm41 = SmUtil.sm4(salt.getBytes()); String decryptStr = sm41.decryptStr(encryptedMessage, CharsetUtil.CHARSET_UTF_8); return decryptStr; } }
#属性文件加密
jasypt:
encryptor:
#salt必须为16位字符串
salt: ya024uspkidtclu3
bean: customStringEncryptor
标签:ISE 集成 div import 简单 解密 salt alt group
原文地址:https://www.cnblogs.com/qiankun-site/p/14926141.html