Jasypt 암호화
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ public class AutoSchedulesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 매일 오후 5시 마다 실행되는 스케줄러
|
// 매일 오후 5시 마다 실행되는 스케줄러
|
||||||
@Scheduled(cron = "5 * * * * ?")
|
@Scheduled(cron = "0 1 * * * ?")
|
||||||
public void fetchSmsAutoSenTest() {
|
public void fetchSmsAutoSenTest() {
|
||||||
portIn.sendAutoSmsTest();
|
portIn.sendAutoSmsTest();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,13 +24,15 @@ spring:
|
|||||||
thymeleaf:
|
thymeleaf:
|
||||||
# 타임리프 템플릿 캐시 비활성화 (개발 환경에서는 false 로 설정 권장)
|
# 타임리프 템플릿 캐시 비활성화 (개발 환경에서는 false 로 설정 권장)
|
||||||
cache: false
|
cache: false
|
||||||
|
# ==============================================
|
||||||
|
# 데이터베이스 설정
|
||||||
|
# ==============================================
|
||||||
datasource:
|
datasource:
|
||||||
kri:
|
kri:
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
jdbc-url: jdbc:postgresql://15.165.180.203:5432/korea_research
|
jdbc-url: ENC(SH5G+4mdOrW3PpVEmVyNXIFyV7eFC6uLTa0e18qa+7ueQeWrduIeGVJLrQP3mUw86dzqLK7AUHjTRuex4ud+rTt026L7csDLFYzLWGkGCTEqfFBOwHng3uQ7n+qmkKiW)
|
||||||
username: ko_research
|
username: ENC(37ccHxlpbsEz8vVcZUZA/j6azKYhP3eHwhOYVjYGf+zKC3u/qc+khKcKuBuE8+Ck)
|
||||||
password: koresearch1@#4
|
password: ENC(uBHyXdI39UzPNvYNHDGfjmMMuhN83xoP8F3wDq/S9DxizhFwbMeEqa36oZ205CBg)
|
||||||
mms:
|
mms:
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
jdbc-url: jdbc:postgresql://15.165.180.203:5432/ko_research_hyunjoo
|
jdbc-url: jdbc:postgresql://15.165.180.203:5432/ko_research_hyunjoo
|
||||||
@@ -45,3 +47,11 @@ spring:
|
|||||||
max-lifetime: 900000
|
max-lifetime: 900000
|
||||||
connection-timeout: 5000
|
connection-timeout: 5000
|
||||||
leak-detection-threshold: 30000
|
leak-detection-threshold: 30000
|
||||||
|
|
||||||
|
# ==============================================
|
||||||
|
# 암호화 설정
|
||||||
|
# ==============================================
|
||||||
|
jasypt:
|
||||||
|
encryptor:
|
||||||
|
password: etribe
|
||||||
|
algorithm: PBEWITHHMACSHA512ANDAES_256
|
||||||
|
|||||||
53
admin/src/test/java/app/module/admin/TestJasyptConfig.java
Normal file
53
admin/src/test/java/app/module/admin/TestJasyptConfig.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
6
pom.xml
6
pom.xml
@@ -180,6 +180,12 @@
|
|||||||
<version>3.1.0</version>
|
<version>3.1.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.ulisesbocchio</groupId>
|
||||||
|
<artifactId>jasypt-spring-boot-starter</artifactId>
|
||||||
|
<version>3.0.5</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
|||||||
Reference in New Issue
Block a user