[Issue] Jasypt | JeongKeepsCalm

[Issue] Jasypt

  • Jasypt
    • 기본 암호화 기능을 추가할 수 있도록 하는 Java 라이브러리
    • 설정파일에 하드코딩된 정보를 암호화해서 관리
  1. dependency 추가

    1
    2
    
     # build.gradle file
     implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5'
    
  2. 아래 사이트에서 하드 코딩 된 정보 암호화
    https://www.devglan.com/online-tools/jasypt-online-encryption-decryption

  3. Java Code

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
     @Configuration
     @EnableEncryptableProperties
     public class JasyptConfig {
    
         @Value("${encryptor.key}")
         private String KEY;
    
         @Bean("jasyptStringEncryptor")
         public StringEncryptor jasyptEncryptor() {
             PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
             SimpleStringPBEConfig config = new SimpleStringPBEConfig();
             config.setPassword(KEY);
             config.setAlgorithm("PBEWithMD5AndDES");
             config.setKeyObtentionIterations("1000");
             config.setPoolSize("1");
             config.setProviderName("SunJCE");
             config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
             config.setStringOutputType("base64");
             encryptor.setConfig(config);
             return encryptor;
         }
     }
    

    @EnableEncryptableProperties: Spring Boot 애플리케이션이 시작될 때 Jasypt를 사용하여 암호화된 속성을 자동으로 복호화

  • encryptor.key 변수 설정 방법
    1. yaml 파일 내 하드 코딩
    2. 인텔리제이 내 Run > Edit Configurations: Environment variables 란에 설정
    3. 운영에 프로젝트 jar 파일을 올려 젠킨스로 배포 시, 변수 지정 명령어 추가