mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update 增加 加密头用来判断数据是否已经被加密了 防止重复加密
This commit is contained in:
		@@ -72,5 +72,10 @@ public interface Constants {
 | 
			
		||||
     */
 | 
			
		||||
    Long TOP_PARENT_ID = 0L;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 加密头
 | 
			
		||||
     */
 | 
			
		||||
    String ENCRYPT_HEADER = "ENC_";
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ import cn.hutool.core.util.ReflectUtil;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.apache.ibatis.io.Resources;
 | 
			
		||||
import org.dromara.common.core.constant.Constants;
 | 
			
		||||
import org.dromara.common.core.utils.ObjectUtils;
 | 
			
		||||
import org.dromara.common.core.utils.StringUtils;
 | 
			
		||||
import org.dromara.common.encrypt.annotation.EncryptField;
 | 
			
		||||
@@ -92,8 +93,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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -103,8 +108,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 decrypt = encryptor.decrypt(value);
 | 
			
		||||
        return StringUtils.removeStart(decrypt, Constants.ENCRYPT_HEADER);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user