更改配置项版本号3.3

This commit is contained in:
seagull 2020-07-07 20:28:33 +08:00
parent b07b3a0012
commit a03f3515a4
5 changed files with 52 additions and 55 deletions

View File

@ -22,7 +22,7 @@
<img alt="code style" src="https://img.shields.io/badge/BUILD-PASSING-green.svg">
</a>
<a href="http://git.oschina.net/seagull1985/LuckyFrameWeb/releases">
<img src="https://img.shields.io/badge/LuckyFrame-V3.2.1 releases-green.svg" >
<img src="https://img.shields.io/badge/LuckyFrame-V3.3 releases-green.svg" >
</a>
</p>

View File

@ -4,7 +4,7 @@
<groupId>LuckyFrameClient</groupId>
<artifactId>LuckyFrameClient</artifactId>
<version>3.2.1</version>
<version>3.3</version>
<packaging>jar</packaging>
<name>LuckyFrameClient</name>

View File

@ -1,5 +1,5 @@
#===============================系统配置=====================================
client.verison=3.2.1
client.verison=3.3
client.name=测试客户端
server.web.ip=localhost
server.web.port=80

View File

@ -17,32 +17,32 @@ import java.security.spec.X509EncodedKeySpec;
public class EncryptionUtils {
/**
* RSA最大加密明文大小
* RSA最大加密明文大小
*/
private static final int MAX_ENCRYPT_BLOCK = 117;
/**
* RSA最大解密密文大小
* RSA最大解密密文大小
*/
private static final int MAX_DECRYPT_BLOCK = 128;
/**
* 默认公钥
* 默认公钥
*/
private static final String DEFAULT_PUBLIC_KEY="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCadmkcep05BmZ3aWH72ab8iw8xD4XYrXmeySwBgKQY4mhHo2MrT8fKiNaG0PC/Jy09inPczBPqf/IPILlE79ujgpc84bHnR27u9IH7kJlyoLiPRGoN+oQbWJakmYTwGkdG4z1Re9xoKi4Ww1WShkvJspMwOWtkwfwub5zkvQtSWQIDAQAB";
/**
* 默认私钥
* 默认私钥
*/
private static final String DEFAULT_PRIVATE_KEY="MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJp2aRx6nTkGZndpYfvZpvyLDzEPhditeZ7JLAGApBjiaEejYytPx8qI1obQ8L8nLT2Kc9zME+p/8g8guUTv26OClzzhsedHbu70gfuQmXKguI9Eag36hBtYlqSZhPAaR0bjPVF73GgqLhbDVZKGS8mykzA5a2TB/C5vnOS9C1JZAgMBAAECgYBNTjYNKtDFWY6u9O81PRl2C6LuyvYSG8Bi2AxONDPswGOwdvWLF8LGevXjQ286PEFIK6MRPpI5Kw/awmX3OpSR10nAzLHo7KU03+1+71EpGcGt0OAudDG+Qzzz10rjyoBwV21d8utoJmy4m5MLbp7yxxZ0caGNfkJMj7QJyxsQAQJBAOtTwyqdGbhLle0rD/9WhK5huFBAaXCw21mJK/wkByVFk9ynHN1P0e3fgS4S2KOyWGEwMgfaxRxvn+Tmj8sQLkkCQQCoCBhihIZj0epYvdQdf63sgrzVlUr3d3IIlKio4JLfvo4gFGpQjV/mOlyS7AGNWf5iDFzJvpXoXET5GYkmpEORAkA784LtAEjlIpx3Z1kT+76hjlOeXkp+Yw/+p2uFOMh5PliFBi3cU9FvgFkwm6yFR5IscFLOnXVJ4UYi0nofiWfBAkBMZvnneci9hIog9ZeIHjEP9FY2a16d7RLNsgKKXyqJT9TB42Z/3/h1751+NI90HTJclLBwDxeMgr/d3+2Lw27xAkBdQqmrWTAmHPGS48CZ/VYu9repRhDmV+8nsWtX1fdU410kcfYgib7WX9Y22v4vGQrVt72waBvvEvbjWjXH+Ael";
/**
* 用户配置的私钥
* 用户配置的私钥
*/
private static String USER_PRIVATE_KEY= SysConfig.getConfiguration().getProperty("client.config.privateKey");
/**
* 用户配置的公钥
* 用户配置的公钥
*/
private static String USER_PUBLIC_KEY= SysConfig.getConfiguration().getProperty("client.config.publicKey");
@ -57,9 +57,9 @@ public class EncryptionUtils {
}
/**
* 获取密钥对
* 获取密钥对
*
* @return 密钥对
* @return 密钥对
*/
public static KeyPair getKeyPair() throws Exception {
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
@ -68,9 +68,9 @@ public class EncryptionUtils {
}
/**
* 获取私钥
* 获取私钥
*
* @param privateKey 私钥字符串
* @param privateKey 私钥字符串
* @return
*/
public static PrivateKey getPrivateKey(String privateKey) throws Exception {
@ -81,9 +81,9 @@ public class EncryptionUtils {
}
/**
* 获取公钥
* 获取公钥
*
* @param publicKey 公钥字符串
* @param publicKey 公钥字符串
* @return
*/
public static PublicKey getPublicKey(String publicKey) throws Exception {
@ -94,10 +94,10 @@ public class EncryptionUtils {
}
/**
* RSA加密
* RSA加密
*
* @param data 待加密数据
* @param publicKey 公钥
* @param data 待加密数据
* @param publicKey 公钥
* @return
*/
public static String encrypt(String data, PublicKey publicKey) throws Exception {
@ -108,7 +108,7 @@ public class EncryptionUtils {
int offset = 0;
byte[] cache;
int i = 0;
// 对数据分段加密
// 对数据分段加密
while (inputLen - offset > 0) {
if (inputLen - offset > MAX_ENCRYPT_BLOCK) {
cache = cipher.doFinal(data.getBytes(), offset, MAX_ENCRYPT_BLOCK);
@ -121,16 +121,16 @@ public class EncryptionUtils {
}
byte[] encryptedData = out.toByteArray();
out.close();
// 获取加密内容使用base64进行编码,并以UTF-8为标准转化成字符串
// 加密后的字符串
// 获取加密内容使用base64进行编码,并以UTF-8为标准转化成字符串
// 加密后的字符串
return new String(Base64.encodeBase64String(encryptedData));
}
/**
* RSA解密
* RSA解密
*
* @param data 待解密数据
* @param privateKey 私钥
* @param data 待解密数据
* @param privateKey 私钥
* @return
*/
public static String decrypt(String data, PrivateKey privateKey) throws Exception {
@ -142,7 +142,7 @@ public class EncryptionUtils {
int offset = 0;
byte[] cache;
int i = 0;
// 对数据分段解密
// 对数据分段解密
while (inputLen - offset > 0) {
if (inputLen - offset > MAX_DECRYPT_BLOCK) {
cache = cipher.doFinal(dataBytes, offset, MAX_DECRYPT_BLOCK);
@ -155,16 +155,16 @@ public class EncryptionUtils {
}
byte[] decryptedData = out.toByteArray();
out.close();
// 解密后的内容
// 解密后的内容
return new String(decryptedData, "UTF-8");
}
/**
* 签名
* 签名
*
* @param data 待签名数据
* @param privateKey 私钥
* @return 签名
* @param data 待签名数据
* @param privateKey 私钥
* @return 签名
*/
public static String sign(String data, PrivateKey privateKey) throws Exception {
byte[] keyBytes = privateKey.getEncoded();
@ -178,12 +178,12 @@ public class EncryptionUtils {
}
/**
* 验签
* 验签
*
* @param srcData 原始字符串
* @param publicKey 公钥
* @param sign 签名
* @return 是否验签通过
* @param srcData 原始字符串
* @param publicKey 公钥
* @param sign 签名
* @return 是否验签通过
*/
public static boolean verify(String srcData, PublicKey publicKey, String sign) throws Exception {
byte[] keyBytes = publicKey.getEncoded();
@ -197,7 +197,7 @@ public class EncryptionUtils {
}
/**
* 加密
* 加密
* @param data
* @return
*/
@ -216,7 +216,7 @@ public class EncryptionUtils {
}
/**
* 解密
* 解密
* @param encryptData
* @return
*/
@ -236,22 +236,22 @@ public class EncryptionUtils {
public static void main(String[] args) {
try {
// 生成密钥对
// 生成密钥对
KeyPair keyPair = getKeyPair();
String privateKey = new String(Base64.encodeBase64(keyPair.getPrivate().getEncoded()));
String publicKey = new String(Base64.encodeBase64(keyPair.getPublic().getEncoded()));
System.out.println("私钥:" + privateKey);
System.out.println("公钥:" + publicKey);
// RSA加密
String data = "待加密的文字内容";
System.out.println("私钥:" + privateKey);
System.out.println("公钥:" + publicKey);
// RSA加密
String data = "待加密的文字内容";
String encryptData = encrypt(data, getPublicKey(publicKey));
System.out.println("加密后内容:" + encryptData);
// RSA解密
System.out.println("加密后内容:" + encryptData);
// RSA解密
String decryptData = decrypt(encryptData, getPrivateKey(privateKey));
System.out.println("解密后内容:" + decryptData);
System.out.println("解密后内容:" + decryptData);
} catch (Exception e) {
e.printStackTrace();
System.out.print("加解密异常");
System.out.print("加解密异常");
}
}
}

View File

@ -3,10 +3,9 @@ package luckyclient.utils.proxy;
import com.alibaba.fastjson.JSONObject;
import luckyclient.netty.ClientHandler;
import luckyclient.utils.EncryptionUtils;
import luckyclient.utils.LogUtil;
import luckyclient.utils.httputils.HttpRequest;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;
@ -16,8 +15,6 @@ import java.util.Properties;
*/
public class PropertiesProxy extends Properties {
private static final Logger log = LoggerFactory.getLogger(PropertiesProxy.class);
private Properties wapper = new Properties();
public Properties getWapper() {
@ -30,7 +27,7 @@ public class PropertiesProxy extends Properties {
@Override
public String getProperty(String key) {
log.info("get config from service");
LogUtil.APP.info("get config from service");
//获取参数
//通过接口获取服务端配置
try{
@ -41,21 +38,21 @@ public class PropertiesProxy extends Properties {
if(res.get("code")!=null&&res.getInteger("code")==200)
{
String value= EncryptionUtils.decrypt(res.get("value").toString());
log.info("get config from server:"+res.toJSONString()+";value="+value);
LogUtil.APP.info("get config from server:"+res.toJSONString()+";value="+value);
return value;
}
}
}catch (Exception e)
{
log.info("服务器没有配置:"+key);
LogUtil.APP.error("服务器没有配置:"+key);
}
return wapper.getProperty(key);
}
@Override
public String getProperty(String key, String defaultValue) {
log.debug("get config from service");
LogUtil.APP.info("get config from service");
//获取参数
//通过接口获取服务端配置
try{
@ -66,7 +63,7 @@ public class PropertiesProxy extends Properties {
}
}catch (Exception e)
{
log.debug("服务器没有配置:"+key);
LogUtil.APP.error("服务器没有配置:"+key);
}
return wapper.getProperty(key, defaultValue);
}