
๐ฑ Spring Boot - Datasource ์ํธํ
๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ์ ๋ณด๋ฅผ ํฌํจํ spring.datasource.url, spring.datasource.username, spring.datasource.password๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ํต์ฌ ๋ฏผ๊ฐ ์ ๋ณด ์ค ํ๋์ด๋ค. ์ด ์ ๋ณด๊ฐ ์ธ๋ถ๋ก ๋ ธ์ถ๋๋ฉด ๋ณด์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์์ผ๋ฏ๋ก, ์ด๋ฅผ ์ํธํํ์ฌ ์์ ํ๊ฒ ๊ด๋ฆฌํ๋ ๋ฐฉ๋ฒ์ด ์ค์ํ๋ค.
Spring Boot์ Jasypt๋ฅผ ํ์ฉํด ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ์ ๋ณด๋ฅผ ์ํธํํ๋ ๋ฐฉ๋ฒ์ ์๊ฐํ ์์ ์ด๋ค.
Jasypt
Jasypt(Java Simplified Encryption)๋ Java ์ ํ๋ฆฌ์ผ์ด์ ์์ ๋ฏผ๊ฐํ ์ ๋ณด๋ฅผ ์ฝ๊ฒ ์ํธํํ๊ณ ๋ณตํธํํ ์ ์๋๋ก ๋์์ฃผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๋ค. Spring Boot์ ํตํฉํ๋ฉด ์ ํ๋ฆฌ์ผ์ด์ ์ค์ ํ์ผ์ ํฌํจ๋ ์ํธํ๋ ๊ฐ์ ์๋์ผ๋ก ๋ณตํธํํ ์ ์๋ค.
Jasypt ์ค์ ํ๊ธฐ
์์กด์ฑ ์ถ๊ฐ
build.gradle ํ์ผ์ Jasypt ์์กด์ฑ ์ถ๊ฐ
dependencies {
implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5'
}
Jasypt Config ์์ฑ
@Configuration
@Slf4j
public class JasyptConfig {
@Bean("jasyptStringEncryptor")
public StringEncryptor stringEncryptor() {
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
// ์ํธํ ํค ์ค์ : ํ๊ฒฝ ๋ณ์ ๋๋ ์์คํ
์์ฑ์์ ์ฝ์
String encryptionKey = System.getenv("JASYPT_ENCRYPTOR_PASSWORD");
if ( StringUtils.isBlank(encryptionKey) ) {
throw new IllegalStateException("JASYPT_ENCRYPTOR_PASSWORD ํ๊ฒฝ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.");
}
// Jasypt ์ํธํ ๊ธฐ๋ณธ ์ค์
config.setPassword(encryptionKey);
config.setAlgorithm("PBEWithMD5AndDES");
config.setKeyObtentionIterations("1000");
config.setPoolSize("1");
config.setProviderName("SunJCE");
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
config.setStringOutputType("base64");
encryptor.setConfig(config);
log.info("Jasypt StringEncryptor๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์ค์ ๋์์ต๋๋ค.");
return encryptor;
}
}
๋ฐ์ดํฐ๋ฒ ์ด์ค ์ ๋ณด ์ํธํ
1. Java ํ๋ก๊ทธ๋จ ํ์ฉํ์ฌ ์ํธํ ๊ฐ ์์ฑ
public class EncryptionUtil {
public static void main(String[] args) {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword("your-secret-key");
encryptor.setAlgorithm("PBEWithMD5AndDES");
String url = encryptor.encrypt("jdbc:mysql://dbIp:dbProt/yourdb");
String username = encryptor.encrypt("username");
String password = encryptor.encrypt("password");
System.out.println("Encrypted URL: ENC(" + url + ")");
System.out.println("Encrypted Username: ENC(" + username + ")");
System.out.println("Encrypted Password: ENC(" + password + ")");
}
}
2. ์ฌ์ดํธ ํ์ฉํ์ฌ ์ํธํ ๊ฐ ์์ฑ
https://www.devglan.com/online-tools/jasypt-online-encryption-decryption
Jasypt Encryption and Decryption Online
Jasypt online free tool for encryption and decryption.This tool supports one way and two way password encryptor using Jasypt as well as matching encrypted password using Jasypt.
www.devglan.com

application.properties ํ์ผ ์ค์
spring.datasource.url=ENC(your-encrypted-url)
spring.datasource.username=ENC(your-encrypted-username)
spring.datasource.password=ENC(your-encrypted-password)
ํ๊ฒฝ ๋ณ์ ์ค์
์ํธํ ํค๋ ํ๊ฒฝ ๋ณ์ ๋๋ ์์คํ ์์ฑ์ผ๋ก ์ ๋ฌํ๋ค.
1. ํฐ์บฃ ๋ฐฐํฌ์ (Windows/Linux ๋ฑ OS ํ๊ฒฝ์์ ์ค์ )
1.1 Windows์์ ํ๊ฒฝ ๋ณ์ ์ค์
๊ณ ๊ธ ์์คํ ์ค์ ์์ ์ค์ ํ๊ฑฐ๋ cmd ์ฐฝ์์ ์๋ ๋ช ๋ น์ด ์ฌ์ฉ
set JASYPT_ENCRYPTOR_PASSWORD=your-secret-key
1.2 Linux์์ ํ๊ฒฝ ๋ณ์ ์ค์
Bash Profile ์ค์ (์: /etc/profile, ~/.bashrc)
export JASYPT_ENCRYPTOR_PASSWORD=your-secret-key
2. VSCode์์ Spring Boot ์คํ์
VSCode์์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํ๋ ค๋ฉด launch.json ํ์ผ์ ์ถ๊ฐํ๊ฑฐ๋ ํฐ๋ฏธ๋์์ ์ง์ ์ค์ ํ๋ค.
2.1 launch.json ํ์ผ์ ์ค์
Run and Debug ํญ์์ create a launch.json file ํด๋ฆญ

launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Spring Boot",
"request": "launch",
"mainClass": "com.example.Application",
"env": {
"JASYPT_ENCRYPTOR_PASSWORD": "your-secret-key"
}
}
]
}
3. Spring Boot Suite, eclipse ์์ ์คํ์
์คํ ์ค์ ์์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ถ๊ฐ
3.1 Run Configurations ์ค์
1. Run → Run Configurations ์ด๋
2. Environment ํญ ํด๋ฆญ
3. ์ ํ๊ฒฝ ๋ณ์ ์ถ๊ฐ
์คํ ๋ฐ ํ ์คํธ
๋ก๊ทธ ํ์ธ
INFO [main] Jasypt StringEncryptor๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์ค์ ๋์์ต๋๋ค.
'Back-end > JAVA & Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [ Spring Security ] ๋์ URL ์ ๊ทผ ๊ถํ ์ ์ด ๊ตฌํ (1) | 2025.04.04 |
|---|---|
| [ Spring Boot ] Jasypt: Spring Boot์์ ๊ฐ๋จํ๊ณ ์์ ํ ์ํธํ (4) | 2025.01.16 |
| [ Spring Boot ] Banner ๋ณ๊ฒฝ (1) | 2024.12.24 |
| [ Spring ] application.properties ๊ฐ๋ฐ์ ์ ์ ๊ฒฝ๊ณ ํด๊ฒฐ (1) | 2024.11.25 |
| [ Spring ] batch ์ค์ผ์ค๋ง ๊ธฐ๊ฐ ์ค์ (3) | 2024.10.08 |