xit-aria 추가

master
mjkhan21 4 months ago
parent c8e3cca90f
commit dce94b45db

Binary file not shown.

@ -76,6 +76,12 @@
<scope>system</scope>
<systemPath>${basedir}/3rd-party/dguard/lib/DguardAPI.jar</systemPath>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.14.0</version>
</dependency>
</dependencies>

@ -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
*/

@ -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;

@ -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);
}
}

@ -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": {

@ -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

Loading…
Cancel
Save