user function 수정

This commit is contained in:
jaewohong
2025-11-06 12:57:14 +09:00
parent 3e16b13d72
commit ce3609583d
5 changed files with 84 additions and 22 deletions
@@ -2,6 +2,7 @@ package com.eactive.eai.transformer.function.crypto;
import java.util.Stack; import java.util.Stack;
import org.apache.commons.lang3.StringUtils;
import org.nfunk.jep.ParseException; import org.nfunk.jep.ParseException;
import org.nfunk.jep.function.PostfixMathCommand; import org.nfunk.jep.function.PostfixMathCommand;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -11,12 +12,17 @@ import com.kjbank.encrypt.exchange.crypto.AES256Cipher;
public class AES256KJDecrypt extends PostfixMathCommand { public class AES256KJDecrypt extends PostfixMathCommand {
public AES256KJDecrypt() { public AES256KJDecrypt() {
numberOfParameters = 1; numberOfParameters = 2;
} }
public void run(Stack inStack) throws ParseException { public void run(Stack inStack) throws ParseException {
checkStack(inStack); checkStack(inStack);
// USER FUNCTION에서 Parameter 에서 가져옴
Object param2 = inStack.pop();
String param2Str = String.valueOf(param2); // null 안전 처리
String decryptKey = param2Str.substring(10,42);
Object param = inStack.pop(); Object param = inStack.pop();
byte[] value = null; byte[] value = null;
@@ -41,8 +47,8 @@ public class AES256KJDecrypt extends PostfixMathCommand {
} }
try { try {
String key = "0123456789abcdefghij0123456789ab"; String decryptedData = AES256Cipher.decrypt(new String(value, StandardCharsets.UTF_8), decryptKey);
String decryptedData = AES256Cipher.decrypt(new String(value, StandardCharsets.UTF_8), key);
inStack.push(decryptedData); inStack.push(decryptedData);
} catch (Exception e) { } catch (Exception e) {
//throw new ExecutionException(e.getMessage(), parameters, e); //throw new ExecutionException(e.getMessage(), parameters, e);
@@ -11,12 +11,17 @@ import com.kjbank.encrypt.exchange.crypto.AES256Cipher;
public class AES256KJEncrypt extends PostfixMathCommand { public class AES256KJEncrypt extends PostfixMathCommand {
public AES256KJEncrypt() { public AES256KJEncrypt() {
numberOfParameters = 1; numberOfParameters = 2;
} }
public void run(Stack inStack) throws ParseException { public void run(Stack inStack) throws ParseException {
checkStack(inStack); checkStack(inStack);
// USER FUNCTION에서 client_secret_key Parameter 에서 가져옴
Object param2 = inStack.pop();
String param2Str = String.valueOf(param2); // null 안전 처리
String encryptKey = param2Str.substring(10,42);
Object param = inStack.pop(); Object param = inStack.pop();
byte[] value = null; byte[] value = null;
@@ -41,8 +46,8 @@ public class AES256KJEncrypt extends PostfixMathCommand {
} }
try { try {
String key = "0123456789abcdefghij0123456789ab"; String encryptedData = AES256Cipher.encrypt(new String(value, StandardCharsets.UTF_8), encryptKey);
String encryptedData = AES256Cipher.encrypt(new String(value, StandardCharsets.UTF_8), key);
inStack.push(encryptedData); inStack.push(encryptedData);
} catch (Exception e) { } catch (Exception e) {
//throw new ExecutionException(e.getMessage(), parameters, e); //throw new ExecutionException(e.getMessage(), parameters, e);
@@ -0,0 +1,62 @@
package com.eactive.eai.transformer.function.crypto;
import java.util.Stack;
import org.nfunk.jep.ParseException;
import org.nfunk.jep.function.PostfixMathCommand;
import com.eactive.eai.common.property.PropManager;
import java.nio.charset.StandardCharsets;
import com.eactive.eai.common.seed.SeedKJ;
import com.eactive.eai.common.seed.SeedCipher;
import org.apache.commons.lang3.StringUtils;
import java.util.Base64;
public class IniSafeNetKJEncrypt extends PostfixMathCommand {
public IniSafeNetKJEncrypt() {
numberOfParameters = 2;
}
public void run(Stack inStack) throws ParseException {
checkStack(inStack);
// USER FUNCTION에서 Parameter 에서 가져옴
Object param2 = inStack.pop();
String param2Str = String.valueOf(param2); // null 안전 처리
String encryptKey = StringUtils.leftPad(param2Str, 16, '0');
Object param = inStack.pop();
byte[] value = null;
if (param instanceof String) {
value = ((String) param).getBytes();
} else if (param instanceof byte[]) {
value = (byte[]) param;
} else if (param instanceof Double) {
if (((Double) param).doubleValue() == Math.round(((Double) param).doubleValue())) {
value = new Long(Math.round(((Double) param).doubleValue())).toString().getBytes();
} else {
value =((Number) param).toString().getBytes();
}
} else if (param instanceof Number) {
value = ((Number) param).toString().getBytes();
} else if (param == null) {
inStack.push(null);
return;
} else {
throw new ParseException("Function의 파라미터 인수가 byte[] 또는 String이 아닙니다. : " + param);
}
try {
String encryptedData = SeedKJ.encrypt(new String(value, StandardCharsets.UTF_8), encryptKey);
inStack.push(encryptedData);
} catch (Exception e) {
//throw new ExecutionException(e.getMessage(), parameters, e);
throw new ParseException(e.getMessage(), e);
}
}
}
@@ -23,7 +23,7 @@ public class SeedKJDecrypt extends PostfixMathCommand {
public void run(Stack inStack) throws ParseException { public void run(Stack inStack) throws ParseException {
checkStack(inStack); checkStack(inStack);
// 아니면 USER FUNCTION에서 Parameter 에서 가져와야 하나 // USER FUNCTION에서 Parameter 에서 가져
Object param2 = inStack.pop(); Object param2 = inStack.pop();
String param2Str = String.valueOf(param2); // null 안전 처리 String param2Str = String.valueOf(param2); // null 안전 처리
String decryptKey = StringUtils.leftPad(param2Str, 16, '0'); String decryptKey = StringUtils.leftPad(param2Str, 16, '0');
@@ -53,9 +53,8 @@ public class SeedKJDecrypt extends PostfixMathCommand {
try { try {
String decryptedData = SeedKJ.decrypt(new String(value, StandardCharsets.UTF_8), decryptKey); String decryptedData = SeedKJ.decrypt(new String(value, StandardCharsets.UTF_8), decryptKey);
//String decryptedData = SeedUtil.decrypt(new String(value, StandardCharsets.UTF_8),decryptKey); // 이건 광주 jar 사용
inStack.push(decryptedData); inStack.push(decryptedData);
//inStack.push(SeedUtil.encrypt(new String(value, StandardCharsets.UTF_8),"testkey123"));
} catch (Exception e) { } catch (Exception e) {
//throw new ExecutionException(e.getMessage(), parameters, e); //throw new ExecutionException(e.getMessage(), parameters, e);
throw new ParseException(e.getMessage(), e); throw new ParseException(e.getMessage(), e);
@@ -24,13 +24,7 @@ public class SeedKJEncrypt extends PostfixMathCommand {
public void run(Stack inStack) throws ParseException { public void run(Stack inStack) throws ParseException {
checkStack(inStack); checkStack(inStack);
// PROPERTY 에서 가져와야 하나 // USER FUNCTION에서 Parameter 에서 가져옴
//PropManager propManager = PropManager.getInstance();
//String safeDbPath = propManager.getProperty("SafeDB","safedb.path");
SeedCipher seedCiper = new SeedCipher();
// 아니면 USER FUNCTION에서 Parameter 에서 가져와야 하나
Object param2 = inStack.pop(); Object param2 = inStack.pop();
String param2Str = String.valueOf(param2); // null 안전 처리 String param2Str = String.valueOf(param2); // null 안전 처리
String encryptKey = StringUtils.leftPad(param2Str, 16, '0'); String encryptKey = StringUtils.leftPad(param2Str, 16, '0');
@@ -59,12 +53,8 @@ public class SeedKJEncrypt extends PostfixMathCommand {
} }
try { try {
//byte[] bbb =seedCiper.encrypt(new String(value, StandardCharsets.UTF_8), encryptKey.getBytes());
//String encryptedData = Base64.getEncoder().encodeToString(bbb);
String encryptedData = SeedKJ.encrypt(new String(value, StandardCharsets.UTF_8), encryptKey); String encryptedData = SeedKJ.encrypt(new String(value, StandardCharsets.UTF_8), encryptKey);
//String encryptedData = SeedUtil.encrypt(new String(value, StandardCharsets.UTF_8),encryptKey);
inStack.push(encryptedData); inStack.push(encryptedData);
} catch (Exception e) { } catch (Exception e) {
//throw new ExecutionException(e.getMessage(), parameters, e); //throw new ExecutionException(e.getMessage(), parameters, e);