admin管理员组

文章数量:1589766

为了避免在配置文件直接明文写敏感信息, 使用加密可以解决尴尬

  • pom文件添加依赖
		<dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>2.1.0</version>
        </dependency>
  • 配置文件中声明加密方式
#jasypt加密的密匙
jasypt:
  encryptor:
    password: EbfYkitulv73I2p0mXI50JMXoaxZTKJ7
  • 获取加密后的信息
@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
public class PasswordTest {

	@Autowired
	StringEncryptor encryptor;

	@Test
	public void getPass() {
		String pass = "ccccccc";

		System.out.println("加密密码: "+encryptor.encrypt(pass));

	}
}
  • 完善配置文件,其中 ENC()为固定格式,括号内为加密后的配置信息
#jasypt加密的密匙
jasypt:
  encryptor:
    password: EbfYkitulv73I2p0mXI50JMXoaxZTKJ7

spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          username: ENC(ZPLrNxi7LgvCThEDxWhSKTtMqh1bitSUMqcHhYFjo5M=)
          uri: ENC(D+BA0BfsYDvQFaWPg2BcEzAjgieC5ljeTcOIBRqtBCj+bFvt2BmjW5tybSUzVkdvn5pqZAjIX5U=)
          password: ENC(d8cI/u82lOmpaazl9+FfkpuYIcIct1Bj)
          search-paths:
server:
  port: 7001

本文标签: 文件加密Springboot