Jasypt 암호화
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user