mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-21 02:25:56 +08:00
枚举类采用class类替换字符串
This commit is contained in:
parent
8320608cb9
commit
0775fd8169
@ -1,5 +1,7 @@
|
|||||||
package com.ruoyi.common.enums;
|
package com.ruoyi.common.enums;
|
||||||
|
|
||||||
|
import com.ruoyi.common.encrypt.IEncryptor;
|
||||||
|
import com.ruoyi.common.encrypt.encryptor.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@ -14,27 +16,27 @@ public enum AlgorithmType {
|
|||||||
/**
|
/**
|
||||||
* base64
|
* base64
|
||||||
*/
|
*/
|
||||||
BASE64("com.ruoyi.common.encrypt.encryptor.Base64Encryptor"),
|
BASE64(Base64Encryptor.class),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* aes
|
* aes
|
||||||
*/
|
*/
|
||||||
AES("com.ruoyi.common.encrypt.encryptor.AesEncryptor"),
|
AES(AesEncryptor.class),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rsa
|
* rsa
|
||||||
*/
|
*/
|
||||||
RSA("com.ruoyi.common.encrypt.encryptor.RsaEncryptor"),
|
RSA(RsaEncryptor.class),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sm2
|
* sm2
|
||||||
*/
|
*/
|
||||||
SM2("com.ruoyi.common.encrypt.encryptor.Sm2Encryptor"),
|
SM2(Sm2Encryptor.class),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sm4
|
* sm4
|
||||||
*/
|
*/
|
||||||
SM4("com.ruoyi.common.encrypt.encryptor.Sm4Encryptor");
|
SM4(Sm4Encryptor.class);
|
||||||
|
|
||||||
private final String clazz;
|
private final Class<? extends IEncryptor> clazz;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import com.ruoyi.common.encrypt.EncryptContext;
|
|||||||
import com.ruoyi.common.encrypt.IEncryptor;
|
import com.ruoyi.common.encrypt.IEncryptor;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.framework.config.properties.EncryptorProperties;
|
import com.ruoyi.framework.config.properties.EncryptorProperties;
|
||||||
import jodd.util.ClassLoaderUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -44,16 +43,7 @@ public class EncryptorManager {
|
|||||||
encryptContext.setPrivateKey(properties.getPrivateKey());
|
encryptContext.setPrivateKey(properties.getPrivateKey());
|
||||||
encryptContext.setPublicKey(properties.getPublicKey());
|
encryptContext.setPublicKey(properties.getPublicKey());
|
||||||
encryptContext.setEncode(properties.getEncode());
|
encryptContext.setEncode(properties.getEncode());
|
||||||
Class<IEncryptor> clazz = null;
|
IEncryptor encryptor = ReflectUtil.newInstance(properties.getAlgorithm().getClazz(), encryptContext);
|
||||||
try {
|
|
||||||
clazz = ClassLoaderUtil.loadClass(properties.getAlgorithm().getClazz());
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
log.error("没有找到配置中指定的加密执行者", e);
|
|
||||||
}
|
|
||||||
if(ObjectUtil.isNull(clazz)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
IEncryptor encryptor = ReflectUtil.newInstance(clazz, encryptContext);
|
|
||||||
encryptorMap.put(encryptorKey, encryptor);
|
encryptorMap.put(encryptorKey, encryptor);
|
||||||
return encryptorMap.get(encryptorKey);
|
return encryptorMap.get(encryptorKey);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user