Springboot database configuration file application.yml set password encryption

In order to strengthen the confidentiality of the database configuration file, the application.yml password encryption function is
implemented as follows:

1. Import xml

<!-- 密码加密使用 -->
<dependency>
  <groupId>com.github.ulisesbocchio</groupId>
  <artifactId>jasypt-spring-boot-starter</artifactId>
  <version>2.1.1</version>
</dependency>

2.yml import

jasypt:
  encryptor:
    password: erp

3. Generate the key

@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TbCloudApplication.class })
@Configuration
public class PasswordTester {

	@Autowired
	private StringEncryptor encryptor;

	@Test
	public void tester() {
		System.err.println("sxnhtc-nh_bank-1 --> " + encryptor.encrypt("sxnhtc-nh_bank-1"));
		System.err.println("1 --> " + encryptor.encrypt("1"));
		
	}
}

4.yml:

password: ENC(ZEtU6okJXwEwzrA0a+TdQ0A4ME+8ehOUpopGSXie6ZQ=)

Guess you like

Origin blog.csdn.net/u014745631/article/details/108302942