|
|
@@ -2,6 +2,7 @@ package com.vber.common.encrypt.core;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
|
+import com.vber.common.core.constant.Constants;
|
|
|
import com.vber.common.core.utils.ObjectUtils;
|
|
|
import com.vber.common.core.utils.StringUtils;
|
|
|
import com.vber.common.encrypt.annotation.EncryptField;
|
|
|
@@ -37,6 +38,7 @@ public class EncryptorManager {
|
|
|
* 缓存加密器
|
|
|
*/
|
|
|
Map<Integer, IEncryptor> encryptorMap = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
/**
|
|
|
* 类加密字段缓存
|
|
|
*/
|
|
|
@@ -90,8 +92,12 @@ public class EncryptorManager {
|
|
|
* @param encryptContext 加密相关的配置信息
|
|
|
*/
|
|
|
public String encrypt(String value, EncryptContext encryptContext) {
|
|
|
+ if (StringUtils.startsWith(value, Constants.ENCRYPT_HEADER)) {
|
|
|
+ return value;
|
|
|
+ }
|
|
|
IEncryptor encryptor = this.registAndGetEncryptor(encryptContext);
|
|
|
- return encryptor.encrypt(value, encryptContext.getEncode());
|
|
|
+ String encrypt = encryptor.encrypt(value, encryptContext.getEncode());
|
|
|
+ return Constants.ENCRYPT_HEADER + encrypt;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -101,8 +107,12 @@ public class EncryptorManager {
|
|
|
* @param encryptContext 加密相关的配置信息
|
|
|
*/
|
|
|
public String decrypt(String value, EncryptContext encryptContext) {
|
|
|
+ if (!StringUtils.startsWith(value, Constants.ENCRYPT_HEADER)) {
|
|
|
+ return value;
|
|
|
+ }
|
|
|
IEncryptor encryptor = this.registAndGetEncryptor(encryptContext);
|
|
|
- return encryptor.decrypt(value);
|
|
|
+ String str = StringUtils.removeStart(value, Constants.ENCRYPT_HEADER);
|
|
|
+ return encryptor.decrypt(str);
|
|
|
}
|
|
|
|
|
|
/**
|