YAML 파일의 패스워드를 암호화하기 위해서 다음과 같이 Maven Dependency를 추가합니다.
<dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>3.0.5</version> </dependency>
import org.jasypt.encryption.StringEncryptor; import org.jasypt.encryption.pbe.PooledPBEStringEncryptor; import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class JasyptConfig { @Bean(name = "jasyptStringEncryptor") public StringEncryptor stringEncryptor() { String key = "my_jasypt_key"; PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); SimpleStringPBEConfig config = new SimpleStringPBEConfig(); config.setPassword(key); // 암호화할 때 사용하는 키 config.setAlgorithm("PBEWithMD5AndDES"); // 암호화 알고리즘 config.setKeyObtentionIterations("1000"); // 반복할 해싱 회수 config.setPoolSize("1"); // 인스턴스 pool config.setProviderName("SunJCE"); config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator"); // salt 생성 클래스 config.setStringOutputType("base64"); //인코딩 방식 encryptor.setConfig(config); return encryptor; } }
이제 https://www.devglan.com/online-tools/jasypt-online-encryption-decryption사이트에서 암호화를 합니다.
https://kitty-geno.tistory.com/160
https://www.baeldung.com/spring-boot-jasypt
spring: datasource: url: asdfasdfasdf username: asdfasdfasdf password: ENC(oBMaRuMSZyJDmebXacU8Vg==) jasypt: encryptor: bean: jasyptStringEncryptor