diff --git a/3rd-party/xit-aria/XAria.dll b/3rd-party/xit-aria/XAria.dll
new file mode 100644
index 0000000..9c946fc
Binary files /dev/null and b/3rd-party/xit-aria/XAria.dll differ
diff --git a/pom.xml b/pom.xml
index b03e659..a26c30f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,6 +76,12 @@
system
${basedir}/3rd-party/dguard/lib/DguardAPI.jar
+
+
+ net.java.dev.jna
+ jna
+ 5.14.0
+
diff --git a/src/main/java/cokr/xit/base/crypto/Cryptography.java b/src/main/java/cokr/xit/base/crypto/Cryptography.java
index df4b529..c223ce8 100644
--- a/src/main/java/cokr/xit/base/crypto/Cryptography.java
+++ b/src/main/java/cokr/xit/base/crypto/Cryptography.java
@@ -21,6 +21,7 @@ import cokr.xit.foundation.data.JSON;
public abstract class Cryptography extends AbstractComponent {
/** 암복호화 설정정보 */
protected CryptoDef def;
+ protected String charset;
/**새 Cryptography을(를) 생성한다.
* @param name 암복호화 설정이름
@@ -106,6 +107,22 @@ public abstract class Cryptography extends AbstractComponent {
return decrypt((String)obj);
}
+ /**문자셋 이름을 반환한다.
+ * @return 문자셋 이름
+ */
+ public String getCharset() {
+ return ifEmpty(charset, () -> charset = ifEmpty(def.settings().string("charset"), "UTF-8"));
+ }
+
+ /**문자셋 이름을 설정한다.
+ * @param charset 문자셋 이름
+ * @return 현재 ARIA
+ */
+ public Cryptography setCharset(String charset) {
+ this.charset = charset;
+ return this;
+ }
+
/**암복호화 지원클래스 설정정보
* @author mjkhan
*/
diff --git a/src/main/java/cokr/xit/base/crypto/bean/ARIA.java b/src/main/java/cokr/xit/base/crypto/bean/ARIA.java
index b9d0e22..6f21b7b 100644
--- a/src/main/java/cokr/xit/base/crypto/bean/ARIA.java
+++ b/src/main/java/cokr/xit/base/crypto/bean/ARIA.java
@@ -35,7 +35,7 @@ public class ARIA extends Cryptography {
* @param key 키
* @return 현재 ARIA
*/
- public ARIA setKey(String key) {
+ public Cryptography setKey(String key) {
this.key = key;
return this;
}
@@ -50,7 +50,7 @@ public class ARIA extends Cryptography {
/**비밀번호 해시값을 설정한다.
* @param hashedPassword 비밀번호 해시값
*/
- public ARIA setHashedPassword(String hashedPassword) {
+ public Cryptography setHashedPassword(String hashedPassword) {
this.hashedPassword = hashedPassword;
return this;
}
@@ -66,7 +66,7 @@ public class ARIA extends Cryptography {
* @param algorithm 알고리즘
* @return 현재 ARIA
*/
- public ARIA setAlgorithm(String algorithm) {
+ public Cryptography setAlgorithm(String algorithm) {
this.algorithm = algorithm;
return this;
}
@@ -82,7 +82,7 @@ public class ARIA extends Cryptography {
* @param blockSize 블록사이즈
* @return 현재 ARIA
*/
- public ARIA setBlockSize(int blockSize) {
+ public Cryptography setBlockSize(int blockSize) {
this.blockSize = blockSize;
return this;
}
@@ -92,15 +92,15 @@ public class ARIA extends Cryptography {
}
@Override
- protected String doEncrypt(String plain) {
- byte[] bytes = encrypt(plain.getBytes());
+ protected String doEncrypt(String plain) throws Exception {
+ byte[] bytes = encrypt(plain.getBytes(getCharset()));
return Base64.getEncoder().encodeToString(bytes);
}
private EgovPasswordEncoder passwordEncoder() {
if (passwordEncoder == null) {
passwordEncoder = new EgovPasswordEncoder();
- passwordEncoder.setHashedPassword(ifEmpty(hashedPassword, hashedPassword = passwordEncoder.encryptPassword(getKey())));
+ passwordEncoder.setHashedPassword(ifEmpty(hashedPassword, () -> hashedPassword = passwordEncoder.encryptPassword(getKey())));
passwordEncoder.setAlgorithm(getAlgorithm());
}
return passwordEncoder;
@@ -120,16 +120,16 @@ public class ARIA extends Cryptography {
}
@Override
- protected String doDecrypt(String encrypted) {
+ protected String doDecrypt(String encrypted) throws Exception {
byte[] bytes = Base64.getDecoder().decode(encrypted);
- return new String(decrypt(bytes));
+ return new String(decrypt(bytes), getCharset());
}
/**현재 설정상태를 비운다.
* @return 현재 ARIA
*/
- public ARIA clear() {
- key = algorithm = null;
+ public Cryptography clear() {
+ charset = key = algorithm = null;
blockSize = 0;
passwordEncoder = null;
aria = null;
diff --git a/src/main/java/cokr/xit/base/crypto/bean/XitAria.java b/src/main/java/cokr/xit/base/crypto/bean/XitAria.java
new file mode 100644
index 0000000..bf8ac99
--- /dev/null
+++ b/src/main/java/cokr/xit/base/crypto/bean/XitAria.java
@@ -0,0 +1,38 @@
+package cokr.xit.base.crypto.bean;
+
+import com.sun.jna.Native;
+import com.sun.jna.win32.StdCallLibrary;
+
+import cokr.xit.base.crypto.Cryptography;
+
+public class XitAria extends Cryptography {
+ private String key;
+
+ public XitAria(String name) {
+ super(name);
+ setKey(def.settings().string("key"));
+ }
+
+ public XitAria setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ @Override
+ protected String doEncrypt(String plain) throws Exception {
+ return Header.INSTANCE.XIT_AriaCrypt_Java(key, plain);
+ }
+
+ @Override
+ protected String doDecrypt(String encrypted) throws Exception {
+ return Header.INSTANCE.XIT_AriaDeCrypt_Java(key, encrypted);
+ }
+
+ public static interface Header extends StdCallLibrary {
+ Header INSTANCE = Native.loadLibrary("3rd-party/xit-aria/XAria", XitAria.Header.class);
+
+ String XIT_AriaCrypt_Java(String AKey, String AValue);
+
+ String XIT_AriaDeCrypt_Java(String AKey, String AValue);
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/xit-crypto.conf b/src/main/resources/xit-crypto.conf
index 9faf127..49a54ec 100644
--- a/src/main/resources/xit-crypto.conf
+++ b/src/main/resources/xit-crypto.conf
@@ -5,10 +5,18 @@
"settings": {
"key": "Copyright (c) 2015 - (주)엑스아이티",
// "hashedPassword": "", // 지정하지 않으면 key로 생성
+ "keySize": 192,
"algorithm": "SHA-256",
"blockSize": 1024
}
},
+ { "name": "xit-aria",
+ "class": "cokr.xit.base.crypto.bean.XitAria",
+ "settings": {
+ "charset": "EUC-KR",
+ "key": "Copyright (c) 2015 - (주)엑스아이티"
+ }
+ },
{ "name": "echelon",
"class": "cokr.xit.base.crypto.bean.Echelon",
"settings": {
diff --git a/src/test/java/cokr/xit/base/crypto/CryptographyTest.java b/src/test/java/cokr/xit/base/crypto/CryptographyTest.java
index b1dfcd8..4487d53 100644
--- a/src/test/java/cokr/xit/base/crypto/CryptographyTest.java
+++ b/src/test/java/cokr/xit/base/crypto/CryptographyTest.java
@@ -10,9 +10,11 @@ import org.junit.jupiter.api.Test;
import cokr.xit.base.crypto.bean.ARIA;
import cokr.xit.base.crypto.bean.DGuard;
import cokr.xit.base.crypto.bean.Echelon;
+import cokr.xit.base.crypto.bean.XitAria;
public class CryptographyTest /* extends TestSupport */ {
private String
+ key = "Copyright (c) 2015 - (주)엑스아이티",
text = "뿌리깊은 나무",
numeric = "1234567890123";
@@ -35,7 +37,7 @@ public class CryptographyTest /* extends TestSupport */ {
@Test
void aria() {
String name = "aria";
- ARIA aria = new ARIA(name);
+ Cryptography aria = new ARIA(name);
Assertions.assertEquals(name, aria.name());
String encrypted = aria.encrypt(text),
@@ -49,6 +51,22 @@ public class CryptographyTest /* extends TestSupport */ {
System.out.println(String.format("text:%s -> encrypted:%s -> decrypted:%s", numeric, encrypted, decrypted));
}
+ @Test
+ void xitAria() {
+ String name = "xit-aria";
+ Cryptography aria = new XitAria(name);
+
+ String str = "7011102177320",
+ encrypted = aria.encrypt(str),
+ decrypted = aria.decrypt(encrypted);
+ System.out.println(String.format("text:%s -> encrypted:%s -> decrypted:%s", str, encrypted, decrypted));
+ Assertions.assertEquals(str, decrypted);
+
+ encrypted = "zyiiAcdcgc9G/UOGT6+W2pL0DfsFYDcCt1Sn9cKk/Ro=";
+ decrypted = aria.decrypt(encrypted);
+ System.out.println(String.format("encrypted: %s -> decrypted: %s", encrypted, decrypted));
+ }
+
@Test
void echelon() {
String name = "echelon";
@@ -74,13 +92,13 @@ public class CryptographyTest /* extends TestSupport */ {
String encrypted = dguard.encrypt(text),
decrypted = dguard.decrypt(encrypted);
- Assertions.assertEquals(text, decrypted);
System.out.println(String.format("text:%s -> encrypted:%s -> decrypted:%s", text, encrypted, decrypted));
+ Assertions.assertEquals(text, decrypted);
encrypted = dguard.encrypt(numeric);
decrypted = dguard.decrypt(encrypted);
- Assertions.assertEquals(numeric, decrypted);
System.out.println(String.format("text:%s -> encrypted:%s -> decrypted:%s", numeric, encrypted, decrypted));
+ Assertions.assertEquals(numeric, decrypted);
}
@Test