CSV 예약발송 시 개인 정보 보호를 위해 CSV 파일을 암호화하여 저장한다.
암호화 처리된 CSV 파일은 설정 파일에 지정된 임시 디렉토리에 생성된다.
common.propertiesUMS.TEMPDIR : 암호화된 CSV 파일이 저장될 디렉토리UMS.TEMPDIR = /Users/UMS-3.5/data/temp
| 항목 | 설명 |
|---|---|
CSV.FILE.CRYPTO.USEYN |
암호화 사용 여부 (Y: 사용, N: 미사용) |
CSV.FILE.CRYPTO.CLASSNAME |
3rd party 암복호화 사용 시 구현 클래스 경로 유라클 기본 암복호화 사용 시 빈 값 |
CSV.FILE.CRYPTO.DOMAIN |
3rd party 암복호화 사용 시 키(도메인) 정보 |
##########################################################################################
# CSV 파일 암/복호화 관련 설정
##########################################################################################
CSV.FILE.CRYPTO.USEYN = Y
CSV.FILE.CRYPTO.CLASSNAME = kr.uracle.ums.extention.util.sample.HmsecFileCrytoSampleService
CSV.FILE.CRYPTO.DOMAIN = D_CM_UNF_01
제공된 커스텀 프로젝트의 lib 폴더에 3rd party 암호화 라이브러리를 추가한다. 예) hmsec-0.9.9-dev_forLink.jar
<dependency>
<groupId>local.lib</groupId>
<artifactId>cryptography</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/hmsec-0.9.9-dev_forLink.jar</systemPath>
</dependency>
배포 시 라이브러리가 WEB-INF/lib 하위에 포함되도록 설정한다.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.sourceDirectory}</directory>
<targetPath>WEB-INF/classes</targetPath>
</resource>
<!--- 추가 부분 --->
<resource>
<directory>${basedir}/lib</directory>
<targetPath>WEB-INF/lib</targetPath>
<includes>
<include>hmsec-0.9.9-dev_forLink.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
제공된 샘플 코드 kr.uracle.ums.extention.util.sample.FileCryptoSampleService.java를 참고하여 아래 두 메서드를 구현한다.
구현 대상 메서드
public void encrypt(File inputFile, File outputFile) throws Exception;
public void decrypt(String password, File inputFile, File outputFile) throws Exception;
@Override
public void encrypt(String password, File inputFile, File outputFile) throws Exception {
byte[] buffer = new byte[1024];
int bytesRead;
try (InputStream fis = new FileInputStream(inputFile);
OutputStream fos = new FileOutputStream(outputFile);
OutputStream cos = new NativeCipherOutputStream(fos, password)) {
while ((bytesRead = fis.read(buffer)) != -1) {
cos.write(buffer, 0, bytesRead);
}
} catch (CryptoKeyException e) {
throw new RuntimeException(e.getMessage());
}
}
@Override
public void decrypt(String password, File inputFile, File outputFile) throws Exception {
byte[] buffer = new byte[1024];
int bytesRead;
try (InputStream fis = new FileInputStream(inputFile);
OutputStream fos = new FileOutputStream(outputFile);
InputStream cis = new NativeCipherInputStream(fis, password)) {
while ((bytesRead = cis.read(buffer)) != -1) {
fos.write(buffer, 0, bytesRead);
}
} catch (CryptoHeaderException e) {
// 암호화되지 않은 파일을 복호화 시도했을 경우 원본 그대로 복사
try (InputStream fis = new FileInputStream(inputFile);
OutputStream fos = new FileOutputStream(outputFile)) {
while ((bytesRead = fis.read(buffer)) != -1) {
fos.write(buffer, 0, bytesRead);
}
}
} catch (CryptoKeyException e) {
throw new RuntimeException(e.getMessage());
}
}
구현한 암복호화 클래스 정보를 common.properties에 설정한다.
##########################################################################################
# CSV 파일 암/복호화 관련 설정
##########################################################################################
CSV.FILE.CRYPTO.USEYN = Y
CSV.FILE.CRYPTO.CLASSNAME = kr.uracle.ums.extention.util.sample.FileCryptoSampleService
CSV.FILE.CRYPTO.DOMAIN = D_CM_UNF_01