<!-- https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter -->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
@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;
}
}
@SpringBootTest
class JasyptConfigTest {
@Test
void contextLoads(){
}
@Test
void jasypt(){
String url = "url";
String username = "username";
String password = "password";
System.out.println(jasyptEncoding(url));
System.out.println(jasyptEncoding(username));
System.out.println(jasyptEncoding(password));
}
public String jasyptEncoding(String value) {
String key = "my_jasypt_key";
StandardPBEStringEncryptor pbeEnc = new StandardPBEStringEncryptor();
pbeEnc.setAlgorithm("PBEWithMD5AndDES");
pbeEnc.setPassword(key);
return pbeEnc.encrypt(value);
}
}
#참고
http://www.jasypt.org/general-usage.html
Jasypt: Java simplified encryption - Jasypt: Java simplified encryption - General Usage
General Usage This section will teach you about the tools jasypt offers you when the easy utilities found in the easy usage page are not enough for your needs. Digesters Digesters are classes specialised in creating message digests (also called hashes) fro
www.jasypt.org
https://bamdule.tistory.com/251
[SpringBoot] application.yml 값 암호화 하기 (jasypt)
application.yml 이나 application.properties 파일에 DB의 비밀번호 또는 키값을 명시해두는 경우가 있습니다. 문제는 중요한 값들이 외부로 노출되어 보안에 심각한 문제를 초래할 수 있다는 점입니다. 이
bamdule.tistory.com
'BACK-END > Spring boot' 카테고리의 다른 글
Spring security (0) | 2022.04.04 |
---|