From 668aca0ff96e021096ba3add447e36a3c05b4535 Mon Sep 17 00:00:00 2001 From: jaewohong Date: Mon, 13 Oct 2025 14:02:17 +0900 Subject: [PATCH] =?UTF-8?q?KJBank=20=EC=95=94=ED=98=B8=ED=99=94=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/eactive/eai/common/seed/SeedKJ.java | 103 ++++++++++ .../eai/common/server/EAIServerVO.java | 3 +- .../encrypt/exchange/crypto/AES256Cipher.java | 188 ++++++++++++++++++ .../exchange/crypto/AES256GCMCipher.java | 69 +++++++ .../encrypt/exchange/crypto/AESCipher.java | 175 ++++++++++++++++ 5 files changed, 537 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/eactive/eai/common/seed/SeedKJ.java create mode 100644 src/main/java/com/kjbank/encrypt/exchange/crypto/AES256Cipher.java create mode 100644 src/main/java/com/kjbank/encrypt/exchange/crypto/AES256GCMCipher.java create mode 100644 src/main/java/com/kjbank/encrypt/exchange/crypto/AESCipher.java diff --git a/src/main/java/com/eactive/eai/common/seed/SeedKJ.java b/src/main/java/com/eactive/eai/common/seed/SeedKJ.java new file mode 100644 index 0000000..225572b --- /dev/null +++ b/src/main/java/com/eactive/eai/common/seed/SeedKJ.java @@ -0,0 +1,103 @@ +package com.eactive.eai.common.seed; + +/** + * 1.16Byte Server Key를 셋팅한다. + * 2.샘플을 보고 사용한다. + * + */ + +public class SeedKJ { + + public static void main(String[] args) throws Exception { + +// System.out.println( Seed.decrypt("47T1fWZ+PqF2pqseL++jLg==")); +// +//// String planText = "AIORTA00051001001R0000AIORULE01 0000001 0821400646003112000000004721212121061705G30011 0000000000006520507000000000000000000000000010200 1000000000000000000000000000000000000000000000000000000000000000000000000011000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000001400000091 90 92 Q 21000000000000000000000004000000000000005000000000000000000000000000004000000000000000000100000000004000000646000000000000000FR00200000000400000000330906REJECT G301 00652 31742FILTER F200 0102721 R001 0000 0000 0000 0000 0000 30840MAIN G300 0061707 06 P3501 P4401 P4601 N4501 P3402 P4201 00000235143TEMP 31955TEMP 00000000231758TEMP 30623TEMP 00004830906BASE00 G301_BASE00 N 000000000000000000000025230906L11210000 G301_L11210000_37 N 000000000000000000000003730906L9Z000007 G301_L9Z000007_42 N 000000000000000000000004230906L9Z000210 G301_L9Z000210_47 N 000000000000000000000004730906CF0342210 G301_CF0342210_26 N 000000000000000000000002630906CF1200610 G301_CF1200610_00 N 000000000000000000000000030906L21210100 G301_L21210100_57 N 000000000000000000000005730906LA0600104 G301_LA0600104_55 N 000000000000000000000005530906LC0000008 G301_LC0000008_00 N 000000000000000000000000030906PE0000026 G301_PE0000026_90 N 000000000000000000000009030906NPF003_D G301_NPF003_D_46 S92 0004631742CD002 CD002_A 0000 N 000000000000000000000000031742FR002 FR002_A 0000 N 000000000000000000000000031742FR003 FR003_A 0000 N 000000000000000000000000031742FR004 FR004_A 0000 N 000000000000000000000000031742FR005 FR005_A 0000 N 000000000000000000000000031742FR006 FR006_A 0000 N 000000000000000000000000031742FR007 FR007_A 0000 N 000000000000000000000000031742IA004 IA004_R R001 N 000000000000000000000102731742LD002 LD002_A 0000 N 000000000000000000000000031742D10210000 D10210000_A 0000 N 000000000000000000000000031742D10210600 D10210600_A 0000 N 000000000000000000000000031742D20210000 D20210000_A 0000 N 000000000000000000000000031742D30210000 D30210000_A 0000 N 000000000000000000000000031742P27000100 P27000100_A 0000 N 000000000000000000000000031742XZ021 XZ021_A 0000 N 000000000000000000000000031742B12000200 B12000200_A 0000 N 000000000000000000000000031742B22000200 B22000200_A 0000 N 000000000000000000000000031742LE0021201 LE0021201_A 0000 N 000000000000000000000000031742L21201300 L21201300_A 0000 N 000000000000000000000000031742NLD010 NLD010_A 0000 N 000000000000000000000000031742G20220L00 G20220L00_A 0000 N 000000000000000000000000030840BASE00 G300_BASE00 N 000000000000000000000026130840NPF003 G300_NPF003_00 S91 0000030840NPF004 G300_NPF004_00 N 000000000000000000000000030840P13000500 G300_P13000500_32 N 000000000000000000000003230840PH0000043 G300_PH0000043_53 P4601 N 000000000000000000000005330840LC0027001 G300_LC0027001_23 P2401 N 000000000000000000000002330840NCBTM206A G300_NCBTM206A_47 P4401 N 000000000000000000000004730840L9Z000006 G300_L9Z000006_29 P3402 N 000000000000000000000002930840L11210000 G300_L11210000_30 N 000000000000000000000003030840U5Z000015 G300_U5Z000015_10 N 000000000000000000000001030840CF1200610 G300_CF1200610_00 N4501 N 000000000000000000000000030840C1Z200031 G300_C1Z200031_77 P3501 N 000000000000000000000007730840CF0642229 G300_CF0642229_09 N 000000000000000000000000930840L21210100 G300_L21210100_46 P4201 N 000000000000000000000004630840LC0000008 G300_LC0000008_00 N 000000000000000000000000030840KCBC14063 G300_KCBC14063_00 N 0000000000000000000000000";//2Byte이상의 문자 취 +// String planText = "";//2Byte이상의 문자 취 +// String testdata = "01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +//// for(int i=0;i<100;i++){ +//// int div =i % 36; +//// char c = testdata.charAt(div); +//// planText += String.valueOf(c); +//// System.out.println("["+planText.getBytes().length+"]["+planText+"]"); +//// String encryptText = Seed.encrypt(planText); +//// //System.out.println("["+encryptText.getBytes().length+"]["+encryptText+"]"); +//// String decryptText = Seed.decrypt(encryptText); +//// System.out.println("["+decryptText.getBytes().length+"]["+decryptText+"]"); +//// +//// if (!planText.equals(decryptText)){ +//// System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); +//// } +//// } +// +// for(int i=0;i<100;i++){ +// int div =i % 36; +// char c = testdata.charAt(div); +// planText += String.valueOf(c); +// System.out.println("["+planText.getBytes().length+"]["+planText+"]"); +// String encryptText = Seed.encryptForLog(planText); +// System.out.println("["+encryptText.getBytes().length+"]["+encryptText+"]"); +// String decryptText = Seed.decryptForLog(encryptText); +// System.out.println("["+decryptText.getBytes().length+"]["+decryptText+"]"); +// +// if (!planText.equals(decryptText)){ +// System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); +// } +// } +// + } + + public static String encrypt(String planText, String key) throws Exception { + SeedCipher seed = new SeedCipher(); + + //String key = "ABCEaicd1234_+|>\n";// 16Byte Server Key + // 1.값셋팅 + String text = planText;//2Byte이상의 문자 취 + + // 2.암호화 + byte[] encryptSeedBytes = seed.encrypt(text, key.getBytes()); + + char[] encryptSeedChars = Base64Coder.encode(encryptSeedBytes); + String encryptText = new String(encryptSeedChars); + + return encryptText; + } + + public static String decrypt(String encryptText, String key) throws Exception { + SeedCipher seed = new SeedCipher(); + + // 3.복호화 + byte[] encryptBytes = Base64Coder.decode(encryptText); + byte[] decryptSeedBytes = seed.decrypt(encryptBytes, key.getBytes()); + String decryptText = new String(decryptSeedBytes); + + // DeCrypt 확인 + return decryptText; + } + public static String encryptForLog(String planText, String key) throws Exception { + SeedCipher seed = new SeedCipher(); + + // 1.값셋팅 + String text = planText;//2Byte이상의 문자 취 + + // 2.암호화 + byte[] encryptSeedBytes = seed.encryptForLog(text.getBytes(), key.getBytes()); + + char[] encryptSeedChars = Base64Coder.encode(encryptSeedBytes); + String encryptText = new String(encryptSeedChars); + + return encryptText; + } + + public static String decryptForLog(String encryptText, String key) throws Exception { + SeedCipher seed = new SeedCipher(); + + // 3.복호화 + byte[] encryptBytes = Base64Coder.decode(encryptText); + byte[] decryptSeedBytes = seed.decryptForLog(encryptBytes, key.getBytes()); + String decryptText = new String(decryptSeedBytes); + + // DeCrypt 확인 + return decryptText; + } +} diff --git a/src/main/java/com/eactive/eai/common/server/EAIServerVO.java b/src/main/java/com/eactive/eai/common/server/EAIServerVO.java index 0fd2815..6f18c02 100644 --- a/src/main/java/com/eactive/eai/common/server/EAIServerVO.java +++ b/src/main/java/com/eactive/eai/common/server/EAIServerVO.java @@ -23,7 +23,8 @@ public class EAIServerVO implements Serializable { * 리모트 호출 url ==> rmi://{ip}:{rmi RegistryPort}/xxxxx * 사이트마다 다를수 있음. */ - private int plusRmiPort = 1; + //private int plusRmiPort = 1; + private int plusRmiPort = 11; //jwhong for weblogic /** * sessionManager에서 쓰기위해 diff --git a/src/main/java/com/kjbank/encrypt/exchange/crypto/AES256Cipher.java b/src/main/java/com/kjbank/encrypt/exchange/crypto/AES256Cipher.java new file mode 100644 index 0000000..38e1f6f --- /dev/null +++ b/src/main/java/com/kjbank/encrypt/exchange/crypto/AES256Cipher.java @@ -0,0 +1,188 @@ +package com.kjbank.encrypt.exchange.crypto; + +//import org.apache.commons.lang.StringUtils; +//import org.apache.log4j.Logger; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.nio.charset.StandardCharsets; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; + +import org.apache.commons.lang3.StringUtils; +import com.eactive.eai.common.util.Logger; + +public class AES256Cipher { + + //private static final Logger logger = Logger.getLogger(AES256Cipher.class); + static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT); + private static final String IV_STRING = "A-16-Byte-String"; + + public static String encrypt(String inPlainText, String inKey) + throws NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { + + String resultData = ""; + + try { + + if(StringUtils.isEmpty(inPlainText)){ + throw new IllegalArgumentException("plainText is Empty"); + } + + if(StringUtils.isEmpty(inKey) || inKey.length() < 32){ + throw new IllegalArgumentException("invalid key"); + } + + if (inKey.length() > 32) { + inKey = inKey.substring(0, 32); + } + logger.debug("[AES256Cipher] Encrypt Key : " + inKey); + + Key key = new SecretKeySpec(inKey.getBytes(StandardCharsets.UTF_8), "AES"); + IvParameterSpec ivParameterSpec = new IvParameterSpec(IV_STRING.getBytes(StandardCharsets.UTF_8)); + + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, key, ivParameterSpec); + + byte[] encryptByte = cipher.doFinal(inPlainText.getBytes(StandardCharsets.UTF_8)); + + resultData = Base64.getEncoder().encodeToString(encryptByte); + + } catch (Exception e) { + logger.error("AES256Cipher Encrypt() : " + e); + throw e; + } + + return resultData; + } + + public static String decrypt(String inEncryptedText, String inKey) + throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException + { + String resultData = ""; + + try { + + if(StringUtils.isEmpty(inEncryptedText)){ + throw new IllegalArgumentException("encryptedText is Empty"); + } + + if(StringUtils.isEmpty(inKey) || inKey.length() < 32){ + throw new IllegalArgumentException("invalid key"); + } + + if (inKey.length() > 32) { + inKey = inKey.substring(0, 32); + } + + logger.debug("[AES256Cipher] Decrypt Key : " + inKey); + + Key key = new SecretKeySpec(inKey.getBytes(StandardCharsets.UTF_8), "AES"); + IvParameterSpec ivParameterSpec = new IvParameterSpec(IV_STRING.getBytes(StandardCharsets.UTF_8)); + + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, key, ivParameterSpec); + + byte[] encryptByte = Base64.getDecoder().decode(inEncryptedText); + + byte[] decryptByte = cipher.doFinal(encryptByte); + + resultData = new String(decryptByte, StandardCharsets.UTF_8); + + } catch (Exception e) { + logger.error("AES256Cipher Decrypt() : " + e); + throw e; + } + + return resultData; + } + + public static String encrypt(String plainText, String iv, String key) + throws NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { + + String resultData = ""; + + byte[] ivBytes; + byte[] keyBytes; + + if (StringUtils.isEmpty(plainText)) { + throw new IllegalArgumentException("plainText is Empty"); + } + + if (StringUtils.isEmpty(iv)) { + throw new IllegalArgumentException("invalid iv"); + } + + if (StringUtils.isEmpty(key)) { + throw new IllegalArgumentException("invalid key"); + } + + ivBytes = Base64.getDecoder().decode(iv); + keyBytes = Base64.getDecoder().decode(key); + + Key keySpec = new SecretKeySpec(keyBytes, "AES"); + IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes); + + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivParameterSpec); + + byte[] encryptByte = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8)); + + resultData = Base64.getEncoder().encodeToString(encryptByte); + + logger.debug("[AES256] Plain Text : " + plainText); + logger.debug("[AES256] Encrypt Text : " + resultData); + + return resultData; + } + + public static String decrypt(String encryptText, String iv, String key) + throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { + + String resultData = ""; + + byte[] ivBytes; + byte[] keyBytes; + + if (StringUtils.isEmpty(encryptText)) { + throw new IllegalArgumentException("encryptText is Empty"); + } + + if (StringUtils.isEmpty(iv)) { + throw new IllegalArgumentException("invalid iv"); + } + + if (StringUtils.isEmpty(key)) { + throw new IllegalArgumentException("invalid key"); + } + + ivBytes = Base64.getDecoder().decode(iv); + keyBytes = Base64.getDecoder().decode(key); + + Key keySpec = new SecretKeySpec(keyBytes, "AES"); + IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes); + + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, keySpec, ivParameterSpec); + + byte[] encryptByte = (Base64.getDecoder().decode(encryptText)); + + byte[] decryptByte = cipher.doFinal(encryptByte); + + resultData = new String(decryptByte, StandardCharsets.UTF_8); + + logger.debug("[AES256] Encrypt Text : " + encryptText); + logger.debug("[AES256] Decrypt Text : " + resultData); + + return resultData; + } + + +} diff --git a/src/main/java/com/kjbank/encrypt/exchange/crypto/AES256GCMCipher.java b/src/main/java/com/kjbank/encrypt/exchange/crypto/AES256GCMCipher.java new file mode 100644 index 0000000..fa49baf --- /dev/null +++ b/src/main/java/com/kjbank/encrypt/exchange/crypto/AES256GCMCipher.java @@ -0,0 +1,69 @@ +package com.kjbank.encrypt.exchange.crypto; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import javax.crypto.spec.GCMParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.security.SecureRandom; +import java.util.Base64; + +public class AES256GCMCipher { + private static final int AES_KEY_SIZE = 256; + private static final int GCM_TAG_LENGTH = 128; + private static final int GCM_IV_LENGTH = 12; + + private final SecretKey key; + + public AES256GCMCipher(byte[] keyBytes) { + if (keyBytes.length != AES_KEY_SIZE / 8) { + throw new IllegalArgumentException("Key must be 256 bits (32 bytes)"); + } + this.key = new SecretKeySpec(keyBytes, "AES"); + } + + public static byte[] generateKey() throws Exception { + KeyGenerator keyGen = KeyGenerator.getInstance("AES"); + keyGen.init(AES_KEY_SIZE); + return keyGen.generateKey().getEncoded(); + } + + public String encrypt(String plaintext, byte[] aad) throws Exception { + byte[] iv = new byte[GCM_IV_LENGTH]; + new SecureRandom().nextBytes(iv); + + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); + GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH, iv); + cipher.init(Cipher.ENCRYPT_MODE, key, spec); + if (aad != null) { + cipher.updateAAD(aad); + } + + byte[] ciphertext = cipher.doFinal(plaintext.getBytes("UTF-8")); + + byte[] encrypted = new byte[iv.length + ciphertext.length]; + System.arraycopy(iv, 0, encrypted, 0, iv.length); + System.arraycopy(ciphertext, 0, encrypted, iv.length, ciphertext.length); + + return Base64.getEncoder().encodeToString(encrypted); + } + + public String decrypt(String encryptedBase64, byte[] aad) throws Exception { + byte[] encrypted = Base64.getDecoder().decode(encryptedBase64); + + byte[] iv = new byte[GCM_IV_LENGTH]; + byte[] ciphertext = new byte[encrypted.length - GCM_IV_LENGTH]; + System.arraycopy(encrypted, 0, iv, 0, GCM_IV_LENGTH); + System.arraycopy(encrypted, GCM_IV_LENGTH, ciphertext, 0, ciphertext.length); + + Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); + GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH, iv); + cipher.init(Cipher.DECRYPT_MODE, key, spec); + if (aad != null) { + cipher.updateAAD(aad); + } + + byte[] plaintext = cipher.doFinal(ciphertext); + return new String(plaintext, "UTF-8"); + } +} diff --git a/src/main/java/com/kjbank/encrypt/exchange/crypto/AESCipher.java b/src/main/java/com/kjbank/encrypt/exchange/crypto/AESCipher.java new file mode 100644 index 0000000..7241637 --- /dev/null +++ b/src/main/java/com/kjbank/encrypt/exchange/crypto/AESCipher.java @@ -0,0 +1,175 @@ +package com.kjbank.encrypt.exchange.crypto; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.io.UnsupportedEncodingException; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +public class AESCipher +{ + private static final String IV_STRING = "A-16-Byte-String"; + private static final String charset = "UTF-8"; + + private static String aesEncryptString(String content, String key) + throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, + InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException + { + byte[] contentBytes = content.getBytes(charset); + byte[] keyBytes = key.getBytes(charset); + byte[] encryptedBytes = aesEncryptBytes(contentBytes, keyBytes); + + return byteArrayToHexString(encryptedBytes); + } + + private static String aesDecryptString(String content, String key) + throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, + IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException + { + byte[] encryptedBytes = hexStringToByteArray(content); + byte[] keyBytes = key.getBytes(charset); + byte[] decryptedBytes = aesDecryptBytes(encryptedBytes, keyBytes); + return new String(decryptedBytes, charset); + } + + private static byte[] aesEncryptBytes(byte[] contentBytes, byte[] keyBytes) + throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, + IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException + { + return cipherOperation(contentBytes, keyBytes, Cipher.ENCRYPT_MODE); + } + + private static byte[] aesDecryptBytes(byte[] contentBytes, byte[] keyBytes) + throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, + IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException + { + return cipherOperation(contentBytes, keyBytes, Cipher.DECRYPT_MODE); + } + + private static byte[] cipherOperation(byte[] contentBytes, byte[] keyBytes, int mode) + throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, + InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException + { + SecretKeySpec secretKey = new SecretKeySpec(keyBytes, "AES"); + + byte[] initParam = IV_STRING.getBytes(charset); + IvParameterSpec ivParameterSpec = new IvParameterSpec(initParam); + + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(mode, secretKey, ivParameterSpec); + + return cipher.doFinal(contentBytes); + } + + public static String encrypt(String inText, String inKey) + { + if (inKey.length() > 16) + { + inKey = inKey.substring(0, 16); + } + + String resultData = ""; + String inNewKey = String.format("%16s", inKey); + + try + { + resultData = AESCipher.aesEncryptString(inText, inNewKey); + } + catch (Exception e) + { + } + + return resultData; + } + + /** + * 복호화 + * + * @param inEncryptedText + * @param inKey + * @return + */ + public static String decrypt(String inEncryptedText, String inKey) + { + if (inKey.length() > 16) + { + inKey = inKey.substring(0, 16); + } + + String inNewKey = String.format("%16s", inKey); + + String resultData = ""; + try + { + resultData = AESCipher.aesDecryptString(inEncryptedText, inNewKey); + } + catch (Exception e) + { + System.out.println(e.toString()); + } + + return resultData; + } + + public static String decryptExistException(String inEncryptedText, String inKey) throws Exception + { + if (inKey.length() > 16) + { + inKey = inKey.substring(0, 16); + } + + String inNewKey = String.format("%16s", inKey); + + String resultData = ""; + + resultData = AESCipher.aesDecryptString(inEncryptedText, inNewKey); + + + return resultData; + } + + /** + * byte 배열을 HEX 문자열로 변환 + * + * @param bytes + * @return + */ + public static String byteArrayToHexString(byte[] bytes) + { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < bytes.length; i++) + { + if (((int) bytes[i] & 0xff) < 0x10) + buffer.append("0"); + buffer.append(Long.toString((int) bytes[i] & 0xff, 16)); + } + return buffer.toString(); + } + + /** + * HEX 문자열을 byte 배열로 변환 + * (ex: "0D0A" => {0x0D, 0x0A,}) + * + * @param inHexString + * @return + */ + public static final byte[] hexStringToByteArray(String inHexString) + { + int i = 0; + byte[] results = new byte[inHexString.length() / 2]; + for (int k = 0; k < inHexString.length(); ) + { + results[i] = (byte) (Character.digit(inHexString.charAt(k++), 16) << 4); + results[i] += (byte) (Character.digit(inHexString.charAt(k++), 16)); + i++; + } + return results; + } + +} +