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,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);
}
}