Created
February 11, 2020 05:50
-
-
Save yevgnenll/99c2d7e0927587398bcec06ffa1bf70b to your computer and use it in GitHub Desktop.
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
package com.idolz.data.batch.config; | |
import org.bouncycastle.jce.provider.BouncyCastleProvider; | |
import org.jasypt.commons.CommonUtils; | |
import org.jasypt.encryption.StringEncryptor; | |
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor; | |
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig; | |
import org.jasypt.salt.RandomSaltGenerator; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.util.Assert; | |
@Configuration | |
public class JasyptEncryptorConfig { | |
@Bean | |
public StringEncryptor jasyptEncryptor(@Value("${jasypt.encryptor.password:none}") String password) { | |
Assert.isTrue(!"none".equals(password), "패스워드를 인자로 넘겨주세요."); | |
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); | |
SimpleStringPBEConfig config = new SimpleStringPBEConfig(); | |
config.setPassword(password); | |
config.setAlgorithm("PBEWITHSHA256AND128BITAES-CBC-BC"); | |
config.setKeyObtentionIterations("1000"); | |
config.setPoolSize(5); | |
config.setProvider(new BouncyCastleProvider()); | |
config.setSaltGenerator(new RandomSaltGenerator()); | |
config.setStringOutputType(CommonUtils.STRING_OUTPUT_TYPE_BASE64); | |
encryptor.setConfig(config); | |
return encryptor; | |
} | |
} |
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
import org.jasypt.encryption.StringEncryptor; | |
import org.junit.jupiter.api.DisplayName; | |
import org.junit.jupiter.api.Test; | |
import org.junit.jupiter.api.extension.ExtendWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit.jupiter.SpringExtension; | |
@ExtendWith(SpringExtension.class) | |
@ContextConfiguration(classes = JasyptEncryptorConfig.class) | |
public class JasyptEncryptorConfigTest { | |
@Autowired | |
private StringEncryptor encryptor; | |
@Test | |
@DisplayName("암호를 생성할때 사용합니다.") | |
public void encryptPassword() { | |
System.out.println("password: ======> " + encryptor.encrypt("rjatorWna2018!@")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment