<foreach../>의 값에 대한 암복호화 지원

master
mjkhan21 1 week ago
parent 92a9c1c2fc
commit a4a4175b9d

@ -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<Cryptography, Object, Object> converter) {
List<Cryptography.TargetValue> 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<String, Object> map = (Map<String, Object>)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;

@ -42,9 +42,9 @@
"targetValues": [ /* 암복호화 대상데이터 설정 */
{ "name": "주민등록번호",
"mapKeys": ["RTPYR_NO", "rtpyrNo"],
"objectProperties": ["rtpyrNo"],
"cryptoDefs": ["aria"] // 암복호화 지원 클래스 설정 이름
"mapKeys": ["RTPYR_NO", "rtpyrNo"], /* 맵이나 DataObject가 암복호화할 값을 가질 경우 값의 키를 지정 */
"objectProperties": ["rtpyrNo"], /* 객체가 암복호화할 값을 가질 경우 값의 프로퍼티 이름을 지정 */
"cryptoDefs": ["aria"] /* 암복호화 수행 클래스 설정(cryptoDef) 이름. 하나만 설정 */
}
]
}

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

Loading…
Cancel
Save