To use the @SpringBootApplication annotation to start the project, you only need to add the maven dependency
We use this jar package to encrypt and decrypt information:
Write encryption and decryption test class:
package cn.linjk.ehome; import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; import org.jasypt.encryption.pbe.config.EnvironmentPBEConfig; import org.junit.Test; public class JasyptTest { @Test public void testEncrypt() throws Exception { StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); EnvironmentPBEConfig config = new EnvironmentPBEConfig(); config.setAlgorithm("PBEWithMD5AndDES"); // 加密的算法,这个算法是默认的 config.setPassword("test"); // 加密的密钥 standardPBEStringEncryptor.setConfig(config); String plainText = "88888888"; String encryptedText = standardPBEStringEncryptor.encrypt(plainText); System.out.println(encryptedText); } @Test public void testDe() throws Exception { StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); EnvironmentPBEConfig config = new EnvironmentPBEConfig(); config.setAlgorithm("PBEWithMD5AndDES"); config.setPassword("test"); standardPBEStringEncryptor.setConfig(config); String encryptedText = "ip10XNIEfAMTGQLdqt87XnLRsshu0rf0"; String plainText = standardPBEStringEncryptor.decrypt(encryptedText); System.out.println(plainText); } }
We got the encryption string, now let’s modify the configuration of application.yml:
Let’s encrypt Just put the string in ENC ({encrypted string}).
You need to configure the secret key during startup
Add the secret key to the startup parameters
The above is the detailed content of How to use the application.yml file to configure database password encryption in the SpringBoot project. For more information, please follow other related articles on the PHP Chinese website!