-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
BE/src/main/java/com/codesquad/airbnb/infra/config/JasyptEncryptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.codesquad.airbnb.infra.config; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor; | ||
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig; | ||
import org.jasypt.salt.StringFixedSaltGenerator; | ||
|
||
import java.util.Scanner; | ||
|
||
public class JasyptEncryptor { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
|
||
String password = System.getenv("JASYPT_PASSWORD"); | ||
|
||
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); | ||
SimpleStringPBEConfig config = new SimpleStringPBEConfig(); | ||
|
||
config.setPassword(password); // 암호화에 사용할 키 | ||
config.setAlgorithm("PBEWithMD5AndDES"); //사용할 알고리즘 | ||
config.setKeyObtentionIterations("1000"); | ||
config.setPoolSize("1"); | ||
config.setSaltGenerator(new StringFixedSaltGenerator("FixedSalt")); | ||
config.setStringOutputType("base64"); | ||
encryptor.setConfig(config); | ||
|
||
while(true) { | ||
System.out.println("암호화를 그만하려면 x를 입력해주세요!"); | ||
|
||
String str = sc.nextLine(); | ||
|
||
if(str.equals("x")) { | ||
break; | ||
} | ||
|
||
String encStr = encryptor.encrypt(str); | ||
String decStr = encryptor.decrypt(encStr); | ||
|
||
System.out.println("str = " + str); | ||
System.out.println("encStr = " + encStr); | ||
System.out.println("decStr = " + decStr); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters