= Properties 암호화 툴 사용 방법 sdl-encrypt는 Spring Framework에서 사용하는 properties를 http://www.jasypt.org/[Jasypt]를 이용해 쉽게 암호화 하기 위한 모듈이다. == 사용 방법 === 파일다운로드 sdl-encrypt-1.0.0.jar 파일을 다운로드 받아서 특정 디렉토리에 복사한다. (배포된 sdl-appendix 내 참조) sdl-encypt-1.0.0.jar 파일을 실행하기 위해서는 JDK 8 이상의 버전이 설치 되어 있어야 한다. ---- C:\encrypt>dir C 드라이브의 볼륨에는 이름이 없습니다. 볼륨 일련 번호: 1841-973A C:\encrypt 디렉터리 2022-08-09 오후 02:17 . 2022-08-09 오후 02:17 .. 2022-08-09 오후 02:15 9,114,144 sdl-encrypt-1.0.0.jar ---- ''' === 암호화 key 파일 생성 같은 폴더에 암호화를 위한 key 파일을 sdl-encrypt-1.0.0.jar 파일을 있는 폴더에 생성한다. key파일의 이름은 *jasypt.key* 로 한다. jasypt.key 파일은 어플리케이션 실행 시 서버에서 읽어 복호화 할때 필요하다. *jasypt.key 파일의 내용이 유출 될 경우 문제가 생길 수 있으니 형상관리에 저장하지 않도록 한다.* *jasypt.key 샘플* ---- fhasiuk23dfjhasoijcnaoijfoase0342ruq0 ---- jasypt.key 파일의 내용은 프로젝트에서 랜덤한 문자열로 생성한다. ''' === Properties 파일 생성 config.properties 파일에 암호화가 필요한 properties를 작성해 sdl-encrypt-1.0.0.jar 파일이 있는 폴더에 생성한다. *config.properties 파일 샘플* ---- # Datasource(Oracle) datasource.driver=net.sf.log4jdbc.sql.jdbcapi.DriverSpy datasource.url=jdbc:log4jdbc:oracle:thin:@10.127.72.226:1521:XE datasource.username=sdl5 datasource.password=dlatl#00 ---- ''' === 암호화 하기 실행 전에 위의 모든 파일들이 같은 폴더에 위치하는지 확인한다. ---- C:\encrypt>dir C 드라이브의 볼륨에는 이름이 없습니다. 볼륨 일련 번호: 1841-973A C:\encrypt 디렉터리 2022-08-09 오후 02:29 . 2022-08-09 오후 02:29 .. 2022-08-08 오후 05:14 407 config.properties 2022-08-09 오후 02:29 37 jasypt.key 2022-08-09 오후 02:15 9,114,144 sdl-encrypt-1.0.0.jar 3개 파일 9,114,588 바이트 ---- *java -jar sdl-encrypt-1.0.0.jar* 실행 ---- C:\encrypt>java -jar sdl-encrypt-1.0.0.jar . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.7.2) 2022-08-09 14:30:33.152 INFO 47544 --- [ main] com.samsung.EncryptApplication : Starting EncryptApplication v1.0.0 using Java 1.8.0_341 on DESKTOP-BBNYDORY with PID 47544 (C:\encrypt\sdl-encrypt-1.0.0.jar started by bbnydory in C:\encrypt) 2022-08-09 14:30:33.157 INFO 47544 --- [ main] com.samsung.EncryptApplication : No active profile set, falling back to 1 default profile: "default" 2022-08-09 14:30:33.456 INFO 47544 --- [ main] ptablePropertiesBeanFactoryPostProcessor : Post-processing PropertySource instances 2022-08-09 14:30:33.458 INFO 47544 --- [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource configurationProperties [class org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource 2022-08-09 14:30:33.461 INFO 47544 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper 2022-08-09 14:30:33.461 INFO 47544 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper 2022-08-09 14:30:33.463 INFO 47544 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper 2022-08-09 14:30:33.464 INFO 47544 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource Config resource 'class path resource [application.properties]' via location 'optional:classpath:/' [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper 2022-08-09 14:30:33.500 INFO 47544 --- [ main] c.u.j.filter.DefaultLazyPropertyFilter : Property Filter custom Bean not found with name 'encryptablePropertyFilter'. Initializing Default Property Filter 2022-08-09 14:30:33.551 INFO 47544 --- [ main] c.u.j.r.DefaultLazyPropertyResolver : Property Resolver custom Bean not found with name 'encryptablePropertyResolver'. Initializing Default Property Resolver 2022-08-09 14:30:33.553 INFO 47544 --- [ main] c.u.j.d.DefaultLazyPropertyDetector : Property Detector custom Bean not found with name 'encryptablePropertyDetector'. Initializing Default Property Detector 2022-08-09 14:30:33.611 INFO 47544 --- [ main] com.samsung.EncryptApplication : Started EncryptApplication in 0.765 seconds (JVM running for 1.669) 2022-08-09 14:30:34.114 INFO 47544 --- [ main] com.samsung.EncryptService : datasource.username=ENC(fOdjJKVr6fkmdS46JlsCRw==) 2022-08-09 14:30:34.115 INFO 47544 --- [ main] com.samsung.EncryptService : datasource.password=ENC(xfWl/qeA7tIMQ10UyU7IInz+SyY6ovX9) 2022-08-09 14:30:34.117 INFO 47544 --- [ main] com.samsung.EncryptService : datasource.url=ENC(Ocp24DAK1cq0f8TezLyMpcedSu6nLdTACSIYyMoCnuanSJT5x76lw8yM0reAeu4qBrBF+yvItVyCBmtPlIv70A==) 2022-08-09 14:30:34.119 INFO 47544 --- [ main] com.samsung.EncryptService : datasource.driver=ENC(GJ527jBO/7Xjilg8WbQHk55GwVUAvc6fIa1Yai1o68WeimiE5BpHNj3e7YnjhtQR) ---- ''' === 확인하기 암호화가 정상적으로 실행 됐다면 같은 폴더에 config-enc.properties 파일이 생성된 것을 확인 할 수 있다. ---- C:\encrypt>dir C 드라이브의 볼륨에는 이름이 없습니다. 볼륨 일련 번호: 1841-973A C:\encrypt 디렉터리 2022-08-09 오후 02:30 . 2022-08-09 오후 02:30 .. 2022-08-09 오후 02:30 305 config-enc.properties 2022-08-08 오후 05:14 407 config.properties 2022-08-09 오후 02:29 37 jasypt.key 2022-08-09 오후 02:15 9,114,144 sdl-encrypt-1.0.0.jar 4개 파일 9,114,893 바이트 ---- config-enc.properties 파일내용 ---- datasource.username=ENC(fOdjJKVr6fkmdS46JlsCRw==) datasource.password=ENC(xfWl/qeA7tIMQ10UyU7IInz+SyY6ovX9) datasource.url=ENC(Ocp24DAK1cq0f8TezLyMpcedSu6nLdTACSIYyMoCnuanSJT5x76lw8yM0reAeu4qBrBF+yvItVyCBmtPlIv70A==) datasource.driver=ENC(GJ527jBO/7Xjilg8WbQHk55GwVUAvc6fIa1Yai1o68WeimiE5BpHNj3e7YnjhtQR) ---- ''' == 고급 사용 sdl-encrypt 모듈을 Spring Boot 프로젝트로 되어 있고 application.properties 파일에 암호화 key파일, Properties 파일, 출력파일에 대한 경로가 작성되어 있다. application.properties 내용 [source,properties] ---- algorithm=PBEWithMD5AndDES keyObtentionIterations=1000 pollSize=1 stringOutputType=base64 keyFilePath=./jasypt.key propertiesFilePath=./config.properties outputPropertiesFilePath=./config-enc.properties ---- 위 내용의 변경이 필요하면 sdl-encrypt-1.0.0.jar 파일이 있는 위치에 application.properties 파일을 새로 작성하고 위의 값들을 오버라이딩해서 사용할 수 있다.