XitAria keySize 추가

master
mjkhan21 4 weeks ago
parent c9efddcbc7
commit bd6845c004

@ -7,12 +7,12 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import cokr.xit.foundation.AbstractComponent; import cokr.xit.foundation.AbstractComponent;
import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.DataObject;
import cokr.xit.foundation.data.JSON; import cokr.xit.foundation.data.JSON;
import cokr.xit.foundation.data.Property;
/** . /** .
* {@link Config } . * {@link Config } .
@ -331,10 +331,15 @@ public abstract class Cryptography extends AbstractComponent {
return false; return false;
} else { } else {
for (String property: valueType.getObjectProperties()) { for (String property: valueType.getObjectProperties()) {
if (Property.readable(obj, property)
&& Property.writeable(obj, property))
return true;
/*
if (PropertyUtils.isReadable(obj, property) if (PropertyUtils.isReadable(obj, property)
&& PropertyUtils.isWriteable(obj, property) && PropertyUtils.isWriteable(obj, property)
) )
return true; return true;
*/
} }
return false; return false;
} }

@ -7,8 +7,6 @@ import java.util.Map;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.ibatis.executor.Executor; import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.executor.resultset.ResultSetHandler; import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.mapping.MappedStatement;
@ -18,6 +16,7 @@ import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.RowBounds;
import cokr.xit.base.crypto.Cryptography.Config; import cokr.xit.base.crypto.Cryptography.Config;
import cokr.xit.foundation.data.Property;
import cokr.xit.foundation.data.paging.MybatisPlugin; import cokr.xit.foundation.data.paging.MybatisPlugin;
/** . /** .
@ -43,6 +42,8 @@ public class CryptographySupport extends MybatisPlugin {
this.cryptos = cryptos.stream().collect(Collectors.toMap(Cryptography::name, crypto -> crypto)); this.cryptos = cryptos.stream().collect(Collectors.toMap(Cryptography::name, crypto -> crypto));
} }
// TODO: 파라미터 추출 및 검사 방식 변경할 것: BoundSql, ParameterMapping을 사용하여 구분 및 추출
@Override @Override
protected Object query(Executor executor, MappedStatement mappedStatement, Object obj, RowBounds rowBounds, ResultHandler<?> resultHandler) throws SQLException { protected Object query(Executor executor, MappedStatement mappedStatement, Object obj, RowBounds rowBounds, ResultHandler<?> resultHandler) throws SQLException {
return encrypt(obj, () -> super.query(executor, mappedStatement, obj, rowBounds, resultHandler)); return encrypt(obj, () -> super.query(executor, mappedStatement, obj, rowBounds, resultHandler));
@ -113,11 +114,16 @@ public class CryptographySupport extends MybatisPlugin {
}); });
} else { } else {
target.getObjectProperties().stream() target.getObjectProperties().stream()
.filter(property -> PropertyUtils.isReadable(obj, property)) .filter(property -> Property.readable(obj, property))
// .filter(property -> PropertyUtils.isReadable(obj, property))
.forEach(property -> { .forEach(property -> {
try { try {
String val = Property.read(obj, property);
Property.write(obj, property, converter.apply(crypto, val));
/*
String val = BeanUtils.getProperty(obj, property); String val = BeanUtils.getProperty(obj, property);
BeanUtils.setProperty(obj, property, converter.apply(crypto, val)); BeanUtils.setProperty(obj, property, converter.apply(crypto, val));
*/
} catch (Exception e) { } catch (Exception e) {
throw runtimeException(e); throw runtimeException(e);
} }

@ -4,12 +4,14 @@ import cokr.xit.base.crypto.Cryptography;
public class XitAria extends Cryptography { public class XitAria extends Cryptography {
private String key; private String key;
private int keySize;
private XitBridge bridge; private XitBridge bridge;
public XitAria(String name) { public XitAria(String name) {
super(name); super(name);
setKey(def.settings().string("key")); setKey(def.settings().string("key"));
bridge = XitBridge.create(key, def.settings().string("charset")); setKeySize(def.settings().number("keySize").intValue());
bridge = XitBridge.create(key, def.settings().string("charset"), keySize);
} }
public XitAria setKey(String key) { public XitAria setKey(String key) {
@ -17,6 +19,11 @@ public class XitAria extends Cryptography {
return this; return this;
} }
public XitAria setKeySize(int keySize) {
this.keySize = keySize< 1 ? 192 : keySize;
return this;
}
@Override @Override
protected String doEncrypt(String plain) throws Exception { protected String doEncrypt(String plain) throws Exception {
return bridge.encrypt(plain); return bridge.encrypt(plain);

@ -313,15 +313,17 @@ public class XitBridge extends AbstractComponent {
throw new IllegalArgumentException("num: " + num); throw new IllegalArgumentException("num: " + num);
} }
public static XitBridge create(String key, String charset) { public static XitBridge create(String key, String charset, int keySize) {
XitBridge newAria = new XitBridge(); XitBridge newAria = new XitBridge();
newAria.encode = true; newAria.encode = true;
newAria.key = ""; newAria.key = "";
newAria.charset = charset; newAria.charset = charset;
newAria.keySize = 192; newAria.keySize = keySize;
newAria.properties.get("Encode").write(true); newAria.properties.get("Encode").write(true);
newAria.properties.get("Key").write(key); newAria.properties.get("Key").write(key);
newAria.properties.get("KeySize").write(keySize);
return newAria; return newAria;
} }

@ -14,7 +14,8 @@
"class": "cokr.xit.base.crypto.bean.XitAria", "class": "cokr.xit.base.crypto.bean.XitAria",
"settings": { "settings": {
"charset": "EUC-KR", "charset": "EUC-KR",
"key": "Copyright (c) 2015 - (주)엑스아이티" "key": "Copyright (c) 2015 - (주)엑스아이티",
"keySize": 192
} }
}, },
{ "name": "echelon", { "name": "echelon",

Loading…
Cancel
Save