Jasypt is a java library which allows the developer to add basic encryption capabilities to his/her projects with minimum effort, and without the need of having deep knowledge on how cryptography works.
compileOnly 'com.github.ulisesbocchio:jasypt-spring-boot:3.0.4'
jasypt:
encryptor:
bean: jasyptStringEncryptor
property:
prefix: ENC(
suffix: )
JasyptConfig.java
import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.springframework.context.annotation.Bean;
@EnableEncryptableProperties
@Configuration
public class JasyptConfig {
@Bean("jasyptStringEncryptor")
public StringEncryptor stringEncryptor() {
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
config.setPassword("testpassword"); //암호화에 사용할 키 -> 중요
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;
}
}
jasyptStringEncryptor
빈을 만들어 준다.build.gradle
tasks.named('test') {
useJUnitPlatform()
systemProperty "jasypt.encryptor.password", System.getProperties().get("jasypt.encryptor.password")
}
@Value("${jasypt.encryptor.password}")
private String encryptKey;
@Bean("jasyptStringEncryptor")
public StringEncryptor stringEncryptor(){
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
config.setPassword(encryptKey);
jobs:
build:
runs-on: ubuntu-latest
env:
JASYPT_PASSWORD: ${secrets.JASYPT_PASSWORD}
spring:
security:
oauth2:
client:
...
registration:
google:
client-id: ENC(3IyFtfCmoSJx/Ox0eDl3fPgjtdaoA/juAFz5WLSld+y1MJXqG9ZqX4g5SPLqOSqht2ISckgiuIyeQ0JEYKJSpYs1uAFMxR5h9xmTjVwSl/tt/FuiB9dCIg==)
client-secret: ENC(7ce2kygTwrk//wZcLo7IZoNRas46P4DW4gDrgFqmCDLx8dOBL4K74Ot8TkQMzRZk)