diff --git a/src/main/java/cokr/xit/base/crypto/bean/XitAria.java b/src/main/java/cokr/xit/base/crypto/bean/XitAria.java index 78e344c..c3aa31d 100644 --- a/src/main/java/cokr/xit/base/crypto/bean/XitAria.java +++ b/src/main/java/cokr/xit/base/crypto/bean/XitAria.java @@ -3,15 +3,17 @@ package cokr.xit.base.crypto.bean; import cokr.xit.base.crypto.Cryptography; public class XitAria extends Cryptography { + private String key; private int keySize; private XitBridge bridge; public XitAria(String name) { super(name); + int version = def.settings().number("version").intValue(); setKey(def.settings().string("key")); setKeySize(def.settings().number("keySize").intValue()); - bridge = XitBridge.create(key, def.settings().string("charset"), keySize); + bridge = XitBridge.create(key, def.settings().string("charset"), keySize, version); } public XitAria setKey(String key) { diff --git a/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java b/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java index cdf25c2..7b41af2 100644 --- a/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java +++ b/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java @@ -24,6 +24,10 @@ public class XitBridge extends AbstractComponent { "KeySize", new KeySize() ); + // version이 1이면 델파이(클린파킹)에서 c++로 작성된 xAria32.dll파일 호출하던 암복호화 방식 + // version이 1이 아닐 경우 델파이(클린파킹)로 작성된 암복호화 방식(cxAria.pas) + int version; + public abstract class Property { public abstract T read(); public abstract void write(T o); @@ -168,8 +172,16 @@ public class XitBridge extends AbstractComponent { // Encryption round key generation rountine // w0 : master key, e : encryption round keys private int encKeySetup(int[] w0, int[] e) { - int R = (keySize + 256) / 32; - int q = (keySize - 128) / 64; + int R, q; + //if(version == 1) { + //R = (128 + 256) / 32; + //q = (128 - 128) / 64; + //} else { + R = (keySize + 256) / 32; + q = (keySize - 128) / 64; + //} + + int i; int[] t = new int[16]; int[] w1 = new int[16]; @@ -220,7 +232,11 @@ public class XitBridge extends AbstractComponent { diffusionLayer(t, w3); for (i = 0; i < 16; i++) { - w3[i] = w3[1] ^ w1[i]; + if(version == 1) { + w3[i] = w3[i] ^ w1[i]; + } else { + w3[i] = w3[1] ^ w1[i]; + } } //e초기화 @@ -297,10 +313,17 @@ public class XitBridge extends AbstractComponent { private void setKey(String value) { if (equals(key, value)) return; - + byte[] hash; try { - byte[] hash = inMD5(key = value); - Delphi.move(hash, 0, masterKey, masterKey.length); + if(version == 1) { + key = value; + hash = key.getBytes(charset); + masterKey = new int[hash.length]; + } else { + hash = inMD5(key = value); + } + + Delphi.move(hash, 0, masterKey, hash.length); } catch (Exception e) { throw runtimeException(e); } @@ -313,11 +336,12 @@ public class XitBridge extends AbstractComponent { throw new IllegalArgumentException("num: " + num); } - public static XitBridge create(String key, String charset, int keySize) { + public static XitBridge create(String key, String charset, int keySize, int version) { XitBridge newAria = new XitBridge(); newAria.encode = true; newAria.key = ""; newAria.charset = charset; + newAria.version = version; newAria.keySize = keySize; newAria.properties.get("Encode").write(true); @@ -344,18 +368,43 @@ public class XitBridge extends AbstractComponent { byte[] value_byte = value.getBytes(charset); + if(version == 1) { + if(value_byte.length % 16 != 0) { + int padCount = 16 - (value_byte.length % 16); + byte[] newByte = new byte[value_byte.length + padCount]; + Arrays.fill(newByte, (byte)0x00); + for(int j=0;j= 0x01 && encryptData[encryptData.length-1] <= 0x0F) { + byte[] newByte = new byte[encryptData.length-encryptData[15]]; + for(int j=0; j