1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > springboot配置文件中的敏感信息加密

springboot配置文件中的敏感信息加密

时间:2019-01-30 20:53:12

相关推荐

springboot配置文件中的敏感信息加密

加上依赖

<!-- 保护springboot配置文件加密--><dependency><groupId>com.github.ulisesbocchio</groupId><artifactId>jasypt-spring-boot-starter</artifactId><version>2.1.0</version></dependency>

配置

# jasypt加密的密匙jasypt:encryptor:password: Y6M9fAJQdU7jNp5MW

package springboot.test;import org.jasypt.encryption.StringEncryptor;import org.junit.Assert;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner;/*** @author cruder* @since /9/17*/@RunWith(SpringRunner.class)@SpringBootTestpublic class DatabaseTest {@Autowiredprivate StringEncryptor encryptor;@Testpublic void getPass() {String url = encryptor.encrypt("jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf-8");String name = encryptor.encrypt("root");String password = encryptor.encrypt("123456");System.out.println("url: " + url);System.out.println("username: " + name);System.out.println("password: " + password);Assert.assertTrue(url.length() > 0);Assert.assertTrue(name.length() > 0);Assert.assertTrue(password.length() > 0);}}

conlose输出:url: f0cuu4F0E5JveF6VbBzF4L8JVlPhDiUAKRauQAMvO71ZdHO8jbFcy39EKGoMQgoc6iOBQY1Fe2h166paeDuMxICoobyZS+oFU36bTh8GUlJJgcItFCohNNaWl5Lv+tzNusername: w70pSwXkQpiwDvRRvUfHIQ==password: NqMKAVdTDda7rVDdIIKPsg==

把配置文件对应部分改了

然后发现居然能正常启动,

盐巴是放在配置文件里的不安全,

为了防止salt(盐)泄露,反解出密码.可以在项目部署的时候使用命令传入salt(盐)

java -jar xxx.jar -Djasypt.encryptor.password=Y6M9fAJQdU7jNp5MW

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。