From b2b60409843f1678b48725c6ce18eebd813b0c64 Mon Sep 17 00:00:00 2001 From: Parker Date: Sat, 13 Feb 2021 00:52:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=8A=A0=E5=AF=86=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/web/system/options/OptionsApi.java | 8 + .../org/opsli/common/enums/OptionsType.java | 10 +- .../filters/aspect/InterfaceCryptoAop.java | 21 +- .../core/utils/CryptoAsymmetricUtil.java | 78 ++++++-- .../utils/EncryptAndDecryptByRsaUtil.java | 182 ------------------ .../org/opsli/core/utils/OptionsUtil.java | 29 +++ .../opsli-core/src/test/java/EncryptTest.java | 26 --- .../opsli-core/src/test/java/RsaTest.java | 79 -------- .../options/web/SysOptionsRestController.java | 12 ++ 9 files changed, 117 insertions(+), 328 deletions(-) delete mode 100644 opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/EncryptAndDecryptByRsaUtil.java delete mode 100644 opsli-base-support/opsli-core/src/test/java/EncryptTest.java delete mode 100644 opsli-base-support/opsli-core/src/test/java/RsaTest.java diff --git a/opsli-api/src/main/java/org/opsli/api/web/system/options/OptionsApi.java b/opsli-api/src/main/java/org/opsli/api/web/system/options/OptionsApi.java index d03421e..4f96f90 100644 --- a/opsli-api/src/main/java/org/opsli/api/web/system/options/OptionsApi.java +++ b/opsli-api/src/main/java/org/opsli/api/web/system/options/OptionsApi.java @@ -29,6 +29,7 @@ import javax.servlet.http.HttpServletResponse; import org.opsli.api.wrapper.system.options.OptionsModel; +import java.util.List; /** @@ -149,4 +150,11 @@ public interface OptionsApi { @GetMapping("/getByCode") ResultVo getByCode(String optionCode); + /** + * 系统参数 查询全部 + * @return ResultVo + */ + @GetMapping("/findAll") + ResultVo> findAll(); + } diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/OptionsType.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/OptionsType.java index 27674b1..02d2462 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/OptionsType.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/enums/OptionsType.java @@ -9,15 +9,19 @@ public enum OptionsType { /** 参数类型 */ - /** 目前支持 RSA SM2 ECIES 3种模式 */ + /** 非对称加密 目前支持 RSA SM2 ECIES 3种模式 */ CRYPTO_ASYMMETRIC("crypto_asymmetric", "加解密-非对称"), + /** 非对称加密 公钥 */ + CRYPTO_ASYMMETRIC_PUBLIC_KEY("crypto_asymmetric_public_key", "加解密-非对称-公钥"), + /** 非对称加密 私钥 */ + CRYPTO_ASYMMETRIC_PRIVATE_KEY("crypto_asymmetric_private_key", "加解密-非对称-私钥"), ; private final String code; private final String desc; - public static OptionsType getCacheType(String cacheType) { + public static OptionsType getType(String cacheType) { OptionsType[] var1 = values(); for (OptionsType type : var1) { if (type.code.equalsIgnoreCase(cacheType)) { @@ -41,4 +45,4 @@ public enum OptionsType { this.code = code; this.desc = desc; } -} \ No newline at end of file +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/filters/aspect/InterfaceCryptoAop.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/filters/aspect/InterfaceCryptoAop.java index 9953b17..22a7523 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/filters/aspect/InterfaceCryptoAop.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/filters/aspect/InterfaceCryptoAop.java @@ -27,14 +27,10 @@ import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.opsli.api.base.encrypt.BaseEncrypt; import org.opsli.api.base.result.ResultVo; -import org.opsli.api.wrapper.system.options.OptionsModel; import org.opsli.common.annotation.InterfaceCrypto; -import org.opsli.common.enums.CryptoAsymmetricType; -import org.opsli.common.enums.OptionsType; import org.opsli.common.exception.ServiceException; import org.opsli.core.msg.CoreMsg; import org.opsli.core.utils.CryptoAsymmetricUtil; -import org.opsli.core.utils.OptionsUtil; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @@ -72,22 +68,13 @@ public class InterfaceCryptoAop { // 返回结果 Object returnValue; - // 获得系统配置参数 非对称加密枚举 - CryptoAsymmetricType asymmetricType = null; - OptionsModel optionsModel = OptionsUtil.getOptionByCode(OptionsType.CRYPTO_ASYMMETRIC); - if(optionsModel != null){ - // 获得加密类型 - asymmetricType = CryptoAsymmetricType.getCryptoType( - optionsModel.getOptionValue()); - } - MethodSignature signature = (MethodSignature) point.getSignature(); // 获得 方法 Method method = signature.getMethod(); // 获得方法注解 InterfaceCrypto annotation = method.getAnnotation(InterfaceCrypto.class); - if(asymmetricType != null && annotation != null){ + if(annotation != null){ // 1. 拆解请求数据 // request 解密 @@ -100,7 +87,7 @@ public class InterfaceCryptoAop { BaseEncrypt baseEncrypt = (BaseEncrypt) arg; String encryptData = baseEncrypt.getEncryptData(); // 解密对象 - Object dataToObj = CryptoAsymmetricUtil.decryptToObj(asymmetricType, encryptData); + Object dataToObj = CryptoAsymmetricUtil.decryptToObj(encryptData); // 根据方法类型转化对象 Type type = TypeUtil.getParamType(method, i); @@ -136,11 +123,11 @@ public class InterfaceCryptoAop { if(returnValue instanceof ResultVo){ ResultVo ret = (ResultVo) returnValue; ret.setData( - CryptoAsymmetricUtil.encrypt(asymmetricType, ret.getData()) + CryptoAsymmetricUtil.encrypt(ret.getData()) ); returnValue = ret; }else { - returnValue = CryptoAsymmetricUtil.encrypt(asymmetricType, returnValue); + returnValue = CryptoAsymmetricUtil.encrypt(returnValue); } }catch (Exception e){ // RSA非对称加密失败 diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CryptoAsymmetricUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CryptoAsymmetricUtil.java index 062ba2a..3936691 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CryptoAsymmetricUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CryptoAsymmetricUtil.java @@ -230,11 +230,10 @@ public class CryptoAsymmetricUtil { /** * 加密数据 - * @param cryptoAsymmetricType 枚举 * @param data 数据 * @return String */ - public static String encrypt(final CryptoAsymmetricType cryptoAsymmetricType, final Object data){ + public static String encrypt(final Object data){ JSONObject jsonObject = new JSONObject(); jsonObject.put(CRYPTO_KEY, data); @@ -244,26 +243,47 @@ public class CryptoAsymmetricUtil { try { - OtherCryptoAsymmetricModel cryptoAsymmetric = getCryptoAsymmetric(cryptoAsymmetricType); + // 加解密方式 + OptionsModel cryptoAsymmetric = OptionsUtil.getOptionByCode(OptionsType.CRYPTO_ASYMMETRIC); + // 公钥 + OptionsModel cryptoAsymmetricPublicKey = + OptionsUtil.getOptionByCode(OptionsType.CRYPTO_ASYMMETRIC_PUBLIC_KEY); + // 私钥 + OptionsModel cryptoAsymmetricPrivateKey = + OptionsUtil.getOptionByCode(OptionsType.CRYPTO_ASYMMETRIC_PRIVATE_KEY); + + // 非法验证 + if(cryptoAsymmetric == null || cryptoAsymmetricPublicKey == null || + cryptoAsymmetricPrivateKey == null + ){ + throw new RuntimeException(); + } - // 如果找不到 公私钥 直接返回原始数据 - if(cryptoAsymmetric == null){ + // 加解密方式枚举 + CryptoAsymmetricType cryptoType = CryptoAsymmetricType.getCryptoType( + cryptoAsymmetric.getOptionValue()); + // 非法验证 + if(cryptoType == null){ throw new RuntimeException(); } - switch (cryptoAsymmetricType){ + + switch (cryptoType){ case RSA: - RSA rsa = SecureUtil.rsa(cryptoAsymmetric.getPrivateKey(), cryptoAsymmetric.getPublicKey()); + RSA rsa = SecureUtil.rsa(cryptoAsymmetricPrivateKey.getOptionValue(), + cryptoAsymmetricPublicKey.getOptionValue()); encryptedStr = rsa.encryptBase64( StrUtil.bytes(encryptedStr, CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey); break; case SM2: - SM2 sm2 = SmUtil.sm2(cryptoAsymmetric.getPrivateKey(), cryptoAsymmetric.getPublicKey()); + SM2 sm2 = SmUtil.sm2(cryptoAsymmetricPrivateKey.getOptionValue(), + cryptoAsymmetricPublicKey.getOptionValue()); encryptedStr = sm2.encryptBase64( StrUtil.bytes(encryptedStr, CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey); break; case ECIES: - ECIES ecies = new ECIES(cryptoAsymmetric.getPrivateKey(), cryptoAsymmetric.getPublicKey()); + ECIES ecies = new ECIES(cryptoAsymmetricPrivateKey.getOptionValue(), + cryptoAsymmetricPublicKey.getOptionValue()); encryptedStr = ecies.encryptBase64( StrUtil.bytes(encryptedStr, CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey); break; @@ -280,13 +300,12 @@ public class CryptoAsymmetricUtil { /** * RSA 解密数据 - * @param cryptoAsymmetricType 枚举 * @param data 数据 * @return Object */ - public static Object decryptToObj(final CryptoAsymmetricType cryptoAsymmetricType, final String data){ + public static Object decryptToObj(final String data){ Object obj; - String decryptedData = decrypt(cryptoAsymmetricType, data); + String decryptedData = decrypt(data); try{ obj = JSONObject.parse(decryptedData); }catch (Exception e){ @@ -298,36 +317,53 @@ public class CryptoAsymmetricUtil { /** * 解密数据 - * @param cryptoAsymmetricType 枚举 * @param data 数据 * @return String */ - public static String decrypt(final CryptoAsymmetricType cryptoAsymmetricType, final String data){ + public static String decrypt(final String data){ String decryptStr; try { if(StringUtils.isEmpty(data)){ throw new RuntimeException(); } - OtherCryptoAsymmetricModel cryptoAsymmetric = getCryptoAsymmetric(cryptoAsymmetricType); - // 如果找不到 公私钥 直接返回原始数据 - if(cryptoAsymmetric == null){ + // 加解密方式 + OptionsModel cryptoAsymmetric = OptionsUtil.getOptionByCode(OptionsType.CRYPTO_ASYMMETRIC); + // 公钥 + OptionsModel cryptoAsymmetricPublicKey = + OptionsUtil.getOptionByCode(OptionsType.CRYPTO_ASYMMETRIC_PUBLIC_KEY); + // 私钥 + OptionsModel cryptoAsymmetricPrivateKey = + OptionsUtil.getOptionByCode(OptionsType.CRYPTO_ASYMMETRIC_PRIVATE_KEY); + + // 非法验证 + if(cryptoAsymmetric == null || cryptoAsymmetricPublicKey == null || + cryptoAsymmetricPrivateKey == null + ){ + throw new RuntimeException(); + } + + // 加解密方式枚举 + CryptoAsymmetricType cryptoType = CryptoAsymmetricType.getCryptoType( + cryptoAsymmetric.getOptionValue()); + // 非法验证 + if(cryptoType == null){ throw new RuntimeException(); } String tmp; String currData = data.replaceAll(" ", "+"); - switch (cryptoAsymmetricType){ + switch (cryptoType){ case RSA: - RSA rsa = SecureUtil.rsa(cryptoAsymmetric.getPrivateKey(), cryptoAsymmetric.getPublicKey()); + RSA rsa = SecureUtil.rsa(cryptoAsymmetricPrivateKey.getOptionValue(), cryptoAsymmetricPublicKey.getOptionValue()); tmp = rsa.decryptStr(currData, KeyType.PrivateKey); break; case SM2: - SM2 sm2 = SmUtil.sm2(cryptoAsymmetric.getPrivateKey(), cryptoAsymmetric.getPublicKey()); + SM2 sm2 = SmUtil.sm2(cryptoAsymmetricPrivateKey.getOptionValue(), cryptoAsymmetricPublicKey.getOptionValue()); tmp = sm2.decryptStr(currData, KeyType.PrivateKey); break; case ECIES: - ECIES ecies = new ECIES(cryptoAsymmetric.getPrivateKey(), cryptoAsymmetric.getPublicKey()); + ECIES ecies = new ECIES(cryptoAsymmetricPrivateKey.getOptionValue(), cryptoAsymmetricPublicKey.getOptionValue()); tmp = ecies.decryptStr(currData, KeyType.PrivateKey); break; default: diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/EncryptAndDecryptByRsaUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/EncryptAndDecryptByRsaUtil.java deleted file mode 100644 index d0b73c2..0000000 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/EncryptAndDecryptByRsaUtil.java +++ /dev/null @@ -1,182 +0,0 @@ -/** - * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com - *

- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.opsli.core.utils; - - -import cn.hutool.core.util.CharsetUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.crypto.asymmetric.KeyType; -import cn.hutool.crypto.asymmetric.RSA; -import com.alibaba.fastjson.JSONObject; -import org.opsli.common.exception.ServiceException; -import org.opsli.common.utils.Props; -import org.opsli.core.msg.CoreMsg; - -import java.util.Collection; - -/** - * 非对称加密 RSA 工具类 - * - * @author 周鹏程 - */ -public enum EncryptAndDecryptByRsaUtil { - - /** 默认实例 */ - INSTANCE(); - - /** RSA KEY */ - private final String rsaKey = "data"; - - /** RSA对象 */ - private final RSA rsa; - - EncryptAndDecryptByRsaUtil(){ - this.rsa = this.createRsa(); - } - - - /** - * 生成 RSA 对象 - * @return RSA - */ - public RSA createRsa(){ - return new RSA(); - } - - /** - * 生成 RSA 对象 - * @param publicKey 公钥 - * @param privateKey 私钥 - * @return RSA - */ - public RSA createRsa(String publicKey, String privateKey){ - return new RSA(privateKey, publicKey); - } - - - /** - * 获得公钥 - * @return String - */ - public String getPublicKey(){ - return rsa.getPublicKeyBase64(); - } - - /** - * 获得私钥 - * @return String - */ - public String getPrivateKey(){ - return rsa.getPrivateKeyBase64(); - } - - /** - * RSA 加密数据 - * @param data 数据 - * @return String - */ - public String encryptedData(Object data){ - return this.encryptedData(this.rsa, data); - } - - - /** - * RSA 加密数据 - * @param rsa RSA - * @param data 数据 - * @return String - */ - public String encryptedData(RSA rsa, Object data){ - String encryptedStr; - try { - JSONObject jsonObject = new JSONObject(); - jsonObject.put(rsaKey, data); - encryptedStr = rsa.encryptBase64(StrUtil.bytes(jsonObject.toString(), CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey); - }catch (Exception e){ - // 加密失败 - throw new ServiceException(CoreMsg.OTHER_EXCEPTION_RSA_EN); - } - return encryptedStr; - } - - - /** - * RSA 解密数据 - * @param data 数据 - * @return Object - */ - public Object decryptedDataToObj(String data){ - return this.decryptedDataToObj(this.rsa, data); - } - - /** - * RSA 解密数据 - * @param rsa RSA - * @param data 数据 - * @return Object - */ - public Object decryptedDataToObj(RSA rsa, String data){ - Object obj; - String decryptedData = this.decryptedData(rsa, data); - try{ - obj = JSONObject.parse(decryptedData); - }catch (Exception e){ - // RSA非对称解密反射失败 - throw new ServiceException(CoreMsg.OTHER_EXCEPTION_RSA_REFLEX); - } - return obj; - } - - - - /** - * RSA 解密数据 - * @param data - * @return String - */ - public String decryptedData(String data){ - return this.decryptedData(this.rsa, data); - } - - - - /** - * RSA 解密数据 - * @param rsa RSA - * @param data 数据 - * @return String - */ - public String decryptedData(RSA rsa,String data){ - //解密,因为编码传值时有空格出现 - String decryptStr; - try{ - data = data.replaceAll(" ", "+"); - String tmp = rsa.decryptStr(data, KeyType.PrivateKey); - JSONObject jsonObject = JSONObject.parseObject(tmp); - Object obj = jsonObject.get(rsaKey); - if(obj instanceof Collection){ - decryptStr = jsonObject.getJSONArray(rsaKey).toJSONString(); - }else{ - decryptStr = jsonObject.getJSONObject(rsaKey).toJSONString(); - } - }catch (Exception e){ - // 解密失败 - throw new ServiceException(CoreMsg.OTHER_EXCEPTION_RSA_DE); - } - return decryptStr; - } - -} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/OptionsUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/OptionsUtil.java index 63f0d98..7a989cf 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/OptionsUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/OptionsUtil.java @@ -15,11 +15,14 @@ */ package org.opsli.core.utils; +import cn.hutool.core.collection.CollUtil; +import com.google.common.collect.Maps; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.opsli.api.base.result.ResultVo; import org.opsli.api.web.system.options.OptionsApi; import org.opsli.api.wrapper.system.options.OptionsModel; +import org.opsli.api.wrapper.system.other.crypto.OtherCryptoAsymmetricModel; import org.opsli.common.enums.OptionsType; import org.opsli.core.cache.local.CacheUtil; import org.opsli.core.msg.CoreMsg; @@ -28,6 +31,9 @@ import org.springframework.context.annotation.Lazy; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Map; + import static org.opsli.common.constants.OrderConstants.UTIL_ORDER; /** @@ -122,6 +128,29 @@ public class OptionsUtil { return model; } + /** + * 获得全部配置参数 (慢)仅用于管理解密 + * @return Map + */ + public static Map findAllOptions(){ + ResultVo> optionsApiAll = optionsApi.findAll(); + if(optionsApiAll == null || !optionsApiAll.isSuccess()){ + return null; + } + + List optionsModels = optionsApiAll.getData(); + if(CollUtil.isEmpty(optionsModels)){ + return null; + } + + Map optionsModelMap = Maps.newHashMap(); + for (OptionsModel optionsModel : optionsModels) { + optionsModelMap.put(optionsModel.getOptionCode(), optionsModel); + } + + return optionsModelMap; + } + // ============== 刷新缓存 ============== diff --git a/opsli-base-support/opsli-core/src/test/java/EncryptTest.java b/opsli-base-support/opsli-core/src/test/java/EncryptTest.java deleted file mode 100644 index 39a52b0..0000000 --- a/opsli-base-support/opsli-core/src/test/java/EncryptTest.java +++ /dev/null @@ -1,26 +0,0 @@ -import cn.hutool.crypto.SecureUtil; -import cn.hutool.crypto.SmUtil; -import cn.hutool.crypto.asymmetric.SM2; -import org.junit.Test; - -/** - * @author 周鹏程 - * @date 2021-01-31 5:15 下午 - **/ -public class EncryptTest { - - @Test - public void testEncrypt(){ - - - SM2 sm2 = SmUtil.sm2("MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJqTLKryt+SYq8oHZ/PeFR64Pq2A9qsKZmZFzU6gvkQ37JeCFCYMitxmF7AtlktSktB3dPdxHEppbfSdY1+i140eAqMZga7j4FmjIdnyW1OauiVgaimJLAEyE7uTAAPggrU9kdqgXbA8hIffm5tu6DKRq/t1NpYEO42S/IGK/yoxAgMBAAECgYEAiWu+klwm0LxKPdpHuK7/58e1MVst8PHWB6aW2AhgHxX46NlkQE92RGsfNCnTLDPFAkCxZCrTE/SXJJmn9yY2qoS26OV0PbTGajk96M8lDi9JSmWCNV1eywPecObSyvtPd5jaPtq2jkgNY/hHJjH6kV7UAFZuaSK7jxskfq7uR2ECQQDPfmGjPiMc65+LE9U7jC4LokyUi1yCgN6AY5MgF6fkxUVJD2mtl9BqRK7qE0OnsRb0NzID3PSfa7aA2I0Rlsj/AkEAvrXUBQ6hfuEwD1896qpSJUr7tLidby/3jYwSoewuydDT2duDc2ZCz4/U/1NpxSxWT10ZZi2ExsFZn/3PDylczwJARA3oijkcHSUu69eybVh51bkCswnOasNHtwZxv+niWEdXhTH38EbFxcUHNaDh5MNRiwH7dobm+M7EShg8lJNHEwJAclRdU97OkFr9zeliHCGZd4P5XAFlWHfgJ7p2nR4Teqe3qZ6Aspj2qqpmnd7qxOrsn02H4YqeU+0sBs9I56T7XwJAAg8wHrh/FAPY96mAya0bpv6zm/7bave17vs+8B+fhBEHHuvetfv8Xi/RkXL0rjE4LaTHefoUbZPNbIhNYiN0CQ==", - "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCakyyq8rfkmKvKB2fz3hUeuD6tgParCmZmRc1OoL5EN+yXghQmDIrcZhewLZZLUpLQd3T3cRxKaW30nWNfoteNHgKjGYGu4+BZoyHZ8ltTmrolYGopiSwBMhO7kwAD4IK1PZHaoF2wPISH35ubbugykav7dTaWBDuNkvyBiv8qMQIDAQAB" - - ); - - System.out.println(sm2.getPublicKeyBase64()); - System.out.println(sm2.getPrivateKeyBase64()); - - - } -} diff --git a/opsli-base-support/opsli-core/src/test/java/RsaTest.java b/opsli-base-support/opsli-core/src/test/java/RsaTest.java deleted file mode 100644 index 1b74150..0000000 --- a/opsli-base-support/opsli-core/src/test/java/RsaTest.java +++ /dev/null @@ -1,79 +0,0 @@ -import cn.hutool.core.convert.Convert; -import com.alibaba.fastjson.JSONObject; -import com.google.common.collect.Maps; -import lombok.Data; -import org.junit.Test; -import org.opsli.core.utils.EncryptAndDecryptByRsaUtil; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * Rsa 加密认证 - */ -public class RsaTest { - - - /** - * 加密数据 - */ - @Test - public void getPublicKey(){ - System.out.println(EncryptAndDecryptByRsaUtil.INSTANCE.getPublicKey()); - - } - - /** - * 加密数据 - */ - @Test - public void test(){ - Map map = Maps.newHashMap(); - map.put("test1", 123); - map.put("test2", "aaa"); - -// Test1 t1 = new Test1(); -// t1.setId( "123"); -// t1.setName( "张三"); -// t1.setAge( 16); - - List list = new ArrayList<>(); - list.add(1); - list.add(2); - list.add(111); - - Object parse = JSONObject.parse("{\"username\":\"demo\",\"password\":\"Aa123456\",\"captcha\":\"\",\"uuid\":\"0d3eea43edf19e4ed0e88aae8d56878046a5\"}"); - - // 加密 - String encryptedData = EncryptAndDecryptByRsaUtil.INSTANCE.encryptedData(list); - System.out.println(encryptedData); - - // 解密 - String decryptedData = EncryptAndDecryptByRsaUtil.INSTANCE.decryptedData(encryptedData); - Object decryptedDataToObj = EncryptAndDecryptByRsaUtil.INSTANCE.decryptedDataToObj(encryptedData); - System.out.println(decryptedData); - - // 解密 - List integers = Convert.toList(Integer.class, decryptedDataToObj); - //Map stringObjectMap = Convert.toMap(String.class, Object.class, decryptedData); - //Map stringObjectMap = Convert.toMap(String.class, Object.class, decryptedDataToObj); - - System.out.println(123); - - } - - - -} - -@Data -class Test1 { - - private String id; - - private String name; - - private Integer age; - -} diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/options/web/SysOptionsRestController.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/options/web/SysOptionsRestController.java index a2dada6..92ed07e 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/options/web/SysOptionsRestController.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/options/web/SysOptionsRestController.java @@ -42,6 +42,7 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Method; +import java.util.List; /** @@ -227,4 +228,15 @@ public class SysOptionsRestController extends BaseRestController> findAll() { + return ResultVo.success( + WrapperUtil.transformInstance(IService.findAllList(), OptionsModel.class) + ); + } }