diff --git a/src/main/java/cokr/xit/base/crypto/CryptographySupport.java b/src/main/java/cokr/xit/base/crypto/CryptographySupport.java index a75de14..7649a02 100644 --- a/src/main/java/cokr/xit/base/crypto/CryptographySupport.java +++ b/src/main/java/cokr/xit/base/crypto/CryptographySupport.java @@ -115,15 +115,62 @@ public class CryptographySupport extends MybatisPlugin { } else { target.getObjectProperties().stream() .filter(property -> Property.readable(obj, property)) -// .filter(property -> PropertyUtils.isReadable(obj, property)) + .forEach(property -> { + try { + Object val = Property.value(obj, property); + if (isEmpty(val)) return; + + if (val instanceof String str) { + val = converter.apply(crypto, str); + } else if (val.getClass().isArray()) { + Object[] vals = ((Object[])val).clone(); + for (int i = 0; i < vals.length; ++i) { + vals[i] = converter.apply(crypto, vals[i]); + } + val = vals; + } else if (val instanceof List list) { + val = list.stream() + .map(e -> converter.apply(crypto, e)) + .toList(); + } + Property.write(obj, property, val); + } catch (Exception e) { + throw runtimeException(e); + } + }); + } + } + } + } catch (Exception e) { + throw runtimeException(e); + } + } +/* + private void convert(Object obj, BiFunction converter) { + List targetValues = Cryptography.Config.get().getTargetValues(obj); + if (targetValues.isEmpty()) return; + + try { + for (Cryptography.TargetValue target: targetValues) { + for (String cryptoDef: target.getCryptoDefs()) { + Cryptography crypto = cryptos.get(cryptoDef); + if (crypto == null) continue; + + if (obj instanceof Map) { + Map map = (Map)obj; + target.getMapKeys().stream() + .filter(key -> map.containsKey(key)) + .forEach(key -> { + Object val = map.get(key); + map.put(key, converter.apply(crypto, val)); + }); + } else { + target.getObjectProperties().stream() + .filter(property -> Property.readable(obj, property)) .forEach(property -> { try { String val = Property.read(obj, property); Property.write(obj, property, converter.apply(crypto, val)); -/* - String val = BeanUtils.getProperty(obj, property); - BeanUtils.setProperty(obj, property, converter.apply(crypto, val)); -*/ } catch (Exception e) { throw runtimeException(e); } @@ -135,7 +182,7 @@ public class CryptographySupport extends MybatisPlugin { throw runtimeException(e); } } - +*/ private void decrypt(Object obj) { if (!isEnabled(obj)) return; diff --git a/src/main/resources/xit-crypto.conf b/src/main/resources/xit-crypto.conf index 1e1e480..b89f768 100644 --- a/src/main/resources/xit-crypto.conf +++ b/src/main/resources/xit-crypto.conf @@ -42,9 +42,9 @@ "targetValues": [ /* 암복호화 대상데이터 설정 */ { "name": "주민등록번호", - "mapKeys": ["RTPYR_NO", "rtpyrNo"], - "objectProperties": ["rtpyrNo"], - "cryptoDefs": ["aria"] // 암복호화 지원 클래스 설정 이름 + "mapKeys": ["RTPYR_NO", "rtpyrNo"], /* 맵이나 DataObject가 암복호화할 값을 가질 경우 값의 키를 지정 */ + "objectProperties": ["rtpyrNo"], /* 객체가 암복호화할 값을 가질 경우 값의 프로퍼티 이름을 지정 */ + "cryptoDefs": ["aria"] /* 암복호화 수행 클래스 설정(cryptoDef) 이름. 하나만 설정 */ } ] } \ No newline at end of file diff --git a/src/test/java/cokr/xit/base/crypto/CryptographyTest.java b/src/test/java/cokr/xit/base/crypto/CryptographyTest.java index d035f81..9226bc5 100644 --- a/src/test/java/cokr/xit/base/crypto/CryptographyTest.java +++ b/src/test/java/cokr/xit/base/crypto/CryptographyTest.java @@ -83,8 +83,7 @@ public class CryptographyTest /* extends TestSupport */ { encrypted = aria.encrypt(plain); decrypted = aria.decrypt(encrypted); System.out.println(String.format("plain: %s -> encrypted: %s -> decrypted: %s", plain, encrypted, decrypted)); - System.out.println(aria.decrypt("OBSVd++xen8anRrG5jtFmg==")); - System.out.println(aria.decrypt("ryGrL2tVXRVHEQhYm7ps2g==")); + System.out.println(aria.decrypt("HQMr3qLxAFCtQ4L5WLWssQ==")); } private String md5(String str) {