首先什么是jasypt?
详细网址 : http://www.jasypt.org/
简单来说,就是一个安全框架,用于对一些如数据库密码等重要信息进行加密的框架
这里我记录一下对数据库密码进行加密的操作流程
- ① 对数据库加盐加密得到加密后的密码
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
//加密所需的salt(盐) 随便生成的随机数用做盐值
textEncryptor.setPassword("d6e57398-3604-8686-29fb-6e146xxxxxxx");
//要加密的数据(数据库的用户名或密码)
String password = textEncryptor.encrypt("password");
//查看密码
System.out.println("password:"+password);
- ②在配置文件中配置加密后的数据库密码(如果是yml的话是类似的)
spring.datasource.password=ENC(ekdxAhhfT6D4wSpT0ZdhOsP9OtJubZ/6) #这里格式是ENC( 数据库加密后密码 ),才可以
- ③在配置文件中配置盐值
jasypt.encryptor.password: d6e57398-3604-8686-29fb-6e146xxxxxxx
- 3.1(为了安全可以不在配置文件里面配置) 在启动时配置密钥