암복호화 function 개발
- 암호화모듈서비스(CryptoModuleService)를 호출하여 암복호화 수행하는 function
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.eactive.eai.custom.transformer.function;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.function.PostfixMathCommand;
|
||||
|
||||
import com.eactive.eai.common.security.CryptoModuleService;
|
||||
|
||||
/**
|
||||
* JEP 트랜스포머 함수 — DJB ERP 연동 복호화.
|
||||
*
|
||||
* 사용법: DJBErpDecryt(encBase64, moduleName) DJBErpDecryt(encBase64, moduleName,
|
||||
* groupSeq)
|
||||
*
|
||||
* 파라미터: encBase64 : Base64 인코딩된 암호문 (String) moduleName : DB에 등록된 암호화 모듈명
|
||||
* (String) groupSeq : 키 도출용 그룹 시퀀스 (String, 선택). 미전달 시 빈 context로 호출.
|
||||
*
|
||||
* 반환값: 복호화된 평문 (String)
|
||||
*/
|
||||
public class DJBErpDecryt extends PostfixMathCommand {
|
||||
|
||||
public DJBErpDecryt() {
|
||||
numberOfParameters = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void run(Stack inStack) throws ParseException {
|
||||
checkStack(inStack);
|
||||
|
||||
if (curNumberOfParameters != 2) {
|
||||
throw new ParseException("DJBErpDecryt: 파라미터는 2개개여야 합니다 (encBase64, moduleName");
|
||||
}
|
||||
|
||||
String moduleName = inStack.pop().toString();
|
||||
String encBase64 = inStack.pop().toString();
|
||||
|
||||
try {
|
||||
byte[] cipherBytes = Base64.getDecoder().decode(encBase64.trim());
|
||||
byte[] plainBytes = CryptoModuleService.getInstance().decrypt(moduleName, new HashMap<>(), null, cipherBytes);
|
||||
inStack.push(new String(plainBytes, StandardCharsets.UTF_8));
|
||||
} catch (ParseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new ParseException("DJBErpDecryt 복호화 실패: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.eactive.eai.custom.transformer.function;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.function.PostfixMathCommand;
|
||||
|
||||
import com.eactive.eai.common.security.CryptoModuleService;
|
||||
|
||||
/**
|
||||
* JEP 트랜스포머 함수 — DJB ERP 연동 암호화.
|
||||
*
|
||||
* 사용법: DJBErpEncryt(plainText, moduleName) DJBErpEncryt(plainText, moduleName,
|
||||
* groupSeq)
|
||||
*
|
||||
* 파라미터: plainText : 암호화할 평문 (String) moduleName : DB에 등록된 암호화 모듈명 (String)
|
||||
* groupSeq : 키 도출용 그룹 시퀀스 (String, 선택). 미전달 시 빈 context로 호출.
|
||||
*
|
||||
* 반환값: Base64 인코딩된 암호문 (String)
|
||||
*/
|
||||
public class DJBErpEncryt extends PostfixMathCommand {
|
||||
|
||||
public DJBErpEncryt() {
|
||||
numberOfParameters = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void run(Stack inStack) throws ParseException {
|
||||
checkStack(inStack);
|
||||
|
||||
if (curNumberOfParameters != 2) {
|
||||
throw new ParseException("DJBErpEncryt: 파라미터는 2개여야 합니다 (plainText, moduleName)");
|
||||
}
|
||||
|
||||
String moduleName = inStack.pop().toString();
|
||||
String plainText = inStack.pop().toString();
|
||||
|
||||
try {
|
||||
byte[] cipherBytes = CryptoModuleService.getInstance().encrypt(moduleName, new HashMap<>(), null,
|
||||
plainText.getBytes(StandardCharsets.UTF_8));
|
||||
inStack.push(Base64.getEncoder().encodeToString(cipherBytes));
|
||||
} catch (ParseException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new ParseException("DJBErpEncryt 암호화 실패: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user