Jasypt 암호화

This commit is contained in:
김현주
2025-07-10 09:18:15 +09:00
parent 86d33788f6
commit e553a99591
5 changed files with 108 additions and 5 deletions

View File

@@ -0,0 +1,34 @@
package app.module.admin.config.application.bean;
import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JasyptConfig {
@Value("${jasypt.encryptor.password}")
private String jasyptPassword;
@Value("${jasypt.encryptor.algorithm}")
private String jasyptAlgorithm;
@Bean("jasyptStringEncryptor")
public StringEncryptor stringEncryptor() {
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
config.setPassword(jasyptPassword); // 암호화할 때 사용하는 키
config.setPoolSize("1"); // 인스턴스 pool
config.setAlgorithm(jasyptAlgorithm); // 암호화 알고리즘
config.setStringOutputType("base64"); // 인코딩 방식
config.setKeyObtentionIterations("1000"); // 반복할 해싱 회수
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator"); // salt 생성 클래스
config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
encryptor.setConfig(config);
return encryptor;
}
}

View File

@@ -30,7 +30,7 @@ public class AutoSchedulesController {
}
// 매일 오후 5시 마다 실행되는 스케줄러
@Scheduled(cron = "5 * * * * ?")
@Scheduled(cron = "0 1 * * * ?")
public void fetchSmsAutoSenTest() {
portIn.sendAutoSmsTest();
}

View File

@@ -24,13 +24,15 @@ spring:
thymeleaf:
# 타임리프 템플릿 캐시 비활성화 (개발 환경에서는 false 로 설정 권장)
cache: false
# ==============================================
# 데이터베이스 설정
# ==============================================
datasource:
kri:
driver-class-name: org.postgresql.Driver
jdbc-url: jdbc:postgresql://15.165.180.203:5432/korea_research
username: ko_research
password: koresearch1@#4
jdbc-url: ENC(SH5G+4mdOrW3PpVEmVyNXIFyV7eFC6uLTa0e18qa+7ueQeWrduIeGVJLrQP3mUw86dzqLK7AUHjTRuex4ud+rTt026L7csDLFYzLWGkGCTEqfFBOwHng3uQ7n+qmkKiW)
username: ENC(37ccHxlpbsEz8vVcZUZA/j6azKYhP3eHwhOYVjYGf+zKC3u/qc+khKcKuBuE8+Ck)
password: ENC(uBHyXdI39UzPNvYNHDGfjmMMuhN83xoP8F3wDq/S9DxizhFwbMeEqa36oZ205CBg)
mms:
driver-class-name: org.postgresql.Driver
jdbc-url: jdbc:postgresql://15.165.180.203:5432/ko_research_hyunjoo
@@ -45,3 +47,11 @@ spring:
max-lifetime: 900000
connection-timeout: 5000
leak-detection-threshold: 30000
# ==============================================
# 암호화 설정
# ==============================================
jasypt:
encryptor:
password: etribe
algorithm: PBEWITHHMACSHA512ANDAES_256

View File

@@ -0,0 +1,53 @@
package app.module.admin;
import org.assertj.core.api.Assertions;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.iv.RandomIvGenerator;
import org.junit.jupiter.api.Test;
public class TestJasyptConfig {
private String jasyptPassword = "etribe";
//PBEWithMD5AndDES
//PBEWITHHMACSHA512ANDAES_256
private String jasyptAlgorithm = "PBEWITHHMACSHA512ANDAES_256";
@Test
void jasypt(){
String url = "jdbc:postgresql://15.165.180.203:5432/korea_research";
String encryptUrl = jasyptEncrypt(url);
System.out.println("encryptUrl : " + encryptUrl);
Assertions.assertThat(url).isEqualTo(jasyptDecryt(encryptUrl));
String username = "ko_research";
String encryptUsername = jasyptEncrypt(username);
System.out.println("encryptUsername : " + encryptUsername);
Assertions.assertThat(username).isEqualTo(jasyptDecryt(encryptUsername));
String password = "koresearch1@#4";
String encryptPassword = jasyptEncrypt(password);
System.out.println("encryptPassword : " + encryptPassword);
Assertions.assertThat(password).isEqualTo(jasyptDecryt(encryptPassword));
}
private String jasyptEncrypt(String input) {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setAlgorithm(jasyptAlgorithm);
encryptor.setPassword(jasyptPassword);
encryptor.setIvGenerator(new RandomIvGenerator());
return encryptor.encrypt(input);
}
private String jasyptDecryt(String input){
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setAlgorithm(jasyptAlgorithm);
encryptor.setPassword(jasyptPassword);
encryptor.setIvGenerator(new RandomIvGenerator());
return encryptor.decrypt(input);
}
}

View File

@@ -180,6 +180,12 @@
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
</dependencies>
<modules>