1.0.10 统一编码UTF-8

This commit is contained in:
yexuejc 2018-06-14 22:32:20 +08:00
parent 3606ba57fa
commit 9ce8d4f216
7 changed files with 151 additions and 41 deletions

View File

@ -1,8 +1,16 @@
uselaw-base 更新内容
-------------------
#### version 1.0.10
**time2018年6月14日22:31:18** <br/>
**branch** master <br/>
**update** <br/>
1. 更新springboot-base:1.1.4依赖
2. 统一编码UTF-8
#
#### version 1.0.9
**time** <br/>
**time2018年6月2日12:17:18** <br/>
**branch** master <br/>
**update** <br/>
1. 更新base依赖

14
pom.xml
View File

@ -5,7 +5,7 @@
<groupId>com.yexuejc.springboot</groupId>
<artifactId>yexuejc-springboot-parent</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
@ -35,7 +35,7 @@
<mybatis-spring-boot-starter.version>1.2.0</mybatis-spring-boot-starter.version>
<mybatis.version>3.4.2</mybatis.version>
<yexuejc.base.version>1.1.3</yexuejc.base.version>
<yexuejc.base.version>1.1.4</yexuejc.base.version>
<jjwt.version>0.7.0</jjwt.version>
<fastjson.version>1.1.46</fastjson.version>
<commons-codec.version>1.10</commons-codec.version>
@ -218,6 +218,15 @@
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<!-- 打包源码 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -253,6 +262,7 @@
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>

View File

@ -9,7 +9,7 @@
<parent>
<groupId>com.yexuejc.springboot</groupId>
<artifactId>yexuejc-springboot-parent</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
<!-- 本地打包:使用相对关联路径 -->
<!--<relativePath>../../yexuejc</relativePath>-->
</parent>

View File

@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.yexuejc.base.http.Resps;
import com.yexuejc.base.util.DateUtil;
import com.yexuejc.base.util.StrUtil;
import com.yexuejc.springboot.base.exception.GatewayException;
import com.yexuejc.springboot.base.filter.ValidationFilter;
import com.yexuejc.springboot.base.filter.ValidationFilterProperties;
import com.yexuejc.springboot.base.interceptor.LogInterceptor;
@ -162,8 +163,11 @@ public class WebAutoConfiguration extends WebMvcConfigurerAdapter {
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Resps<Object> jsonErrorHandler(Throwable e) {
LogUtil.exceptionLogger.error(e.getMessage(), e);
return Resps.error(StrUtil.setStr(e.getMessage(), ERROR_MSG));
LogUtil.exceptionLogger.error("", e);
if (e instanceof GatewayException) {
return Resps.error(StrUtil.setStr(e.getMessage(), ERROR_MSG));
}
return Resps.error(ERROR_MSG);
}
}
}

View File

@ -131,34 +131,40 @@ public class ApplicationTest {
* @throws KeyStoreException
*/
@Test
public void file() throws CertificateException, IOException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {
public void file() throws CertificateException, IOException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, InvalidKeySpecException {
String publicKey = this.getClass().getResource("/lgfishing.cer").getFile().toString();
// String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCX9uSsfJeIDIPzxCtwwFh5vrIKar69i3DPUTDEiKPRdtmADa8Ls6KAsPVpzgtQYoYVpYBoMbBtp0cGRoQULO83NWIAhmsU2cvd0nmGlB2xPRz+uGYW1rsYyCM8RSvfAwCVNsJD10A9voLhRQuYHPIDmay1sBA/casvEvYwMqDZtQIDAQAB";
String privateKey = this.getClass().getResource("/lgfishing.keystore").getFile().toString();
String privatePwd = "lgfishing2018";
String privateAlias = "lgfishing";
String dataStr = "{\"ret\":\"0\",\"expireTime\":\"2015/10/28 23:59:59\",\"rettxt\":\"OK\",\"token\":\"69296128A59798E2D423D3B1A9F766F4\"}";
// String dataStr = "{\"ret\":\"0\",\"expireTime\":\"2015/10/28 23:59:59\",\"rettxt\":\"OK\",\"token\":\"69296128A59798E2D423D3B1A9F766F4\"}";
String dataStr = "{\"foodsCode\":\"49\",\"latlng\":\"22.5,114.0\",\"pageIndex\":1,\"pageSize\":10}";
/***************************************************************************************************************************************************************************************************************************************/
//客户端公钥加密
String publicEncryptResult = RSA.publicEncrypt(dataStr, RSA2.getPublicKey(publicKey));
System.out.println(publicEncryptResult);
System.out.println(StrUtil.toMD5(dataStr));
// String publicEncryptResult = RSA.publicEncrypt(dataStr, RSA2.getPublicKey(publicKey));
// System.out.println(publicEncryptResult);
// System.out.println(StrUtil.toMD5(dataStr));
String publicEncryptResult="MxyCtlTnkvh+0vOPsDDL1+hO9NZ+pDps+uVt8NwJvn4SZoYfjuj2a1WYZrvDk/sUC41zRQAE85/c\ndm9IC0BtFr7CtHSnbJfExSBwHtkG3/pE4hd5ysrdQiaFmlvENJ24cVYX+4WBEZ6bfh9jB3e1QXQi\n05o+uwxOX1UW6VENEx0\u003d\n";
//服务器私钥解密
String privateDecryptResult = RSA.privateDecrypt(publicEncryptResult, RSA2.getPrivateKey(privateKey, privateAlias, privatePwd));
System.out.println(privateDecryptResult);
/***************************************************************************************************************************************************************************************************************************************/
//服务器端私钥加密
String privateEncryptResult = RSA.privateEncrypt(dataStr, RSA2.getPrivateKey(privateKey, privateAlias, privatePwd));
System.out.println(privateEncryptResult);
//客户端公钥解密
String publicDecryptResult = RSA.publicDecrypt(privateEncryptResult, RSA2.getPublicKey(publicKey));
System.out.println(publicDecryptResult);
// //服务器端私钥加密
// String privateEncryptResult = RSA.privateEncrypt(dataStr, RSA2.getPrivateKey(privateKey, privateAlias, privatePwd));
// System.out.println(privateEncryptResult);
//
// //客户端公钥解密
// String publicDecryptResult = RSA.publicDecrypt(privateEncryptResult, RSA2.getPublicKey(publicKey));
// System.out.println(publicDecryptResult);
//
// System.out.println(Base64.getEncoder().encodeToString(RSA2.getPublicKey(publicKey).getEncoded()));
}
@ -170,32 +176,37 @@ public class ApplicationTest {
*/
@Test
public void a() throws NoSuchAlgorithmException, InvalidKeySpecException {
String privateKey = "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAiSo5blJ9-QJ0_QElcy5AaRTq-3oO4lJ8PvIOIt-Xr5SUFODVj3DUbiy6_0bxQYO3NiYHlXPb37UVV3jjlXJsXwIDAQABAkBE0WOJH2hGs93gRl_0vwLf9ffDfkTTdlER_73p70aad3QZRslEkinQH7G5aE_DgBm5m72TCeH-PD2FZ2lwtavBAiEAvnRown5Lpqbl0tN_OUxr_e1u9d_-8dNL_JEETO7BZCECIQC4XtY-18j0bVVLxaXPjKQ00D59yntwObihDNyRK0nAfwIgHPHEGgrnpGQo-Wl7JFIg925mNqfcLxRVsAS6CpcefQECIQCUsLdsmy6QIhTmNRJSXoSXq1KatE_05DhIekzwLs8eFQIgfMawMiu52ZxBI5_pZ7ancQZ6Dsxl45utFqJShzV1pio";
String publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIkqOW5SffkCdP0BJXMuQGkU6vt6DuJSfD7yDiLfl6-UlBTg1Y9w1G4suv9G8UGDtzYmB5Vz29-1FVd445VybF8CAwEAAQ";
String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCX9uSsfJeIDIPzxCtwwFh5vrIKar69i3DPUTDEiKPRdtmADa8Ls6KAsPVpzgtQYoYVpYBoMbBtp0cGRoQULO83NWIAhmsU2cvd0nmGlB2xPRz+uGYW1rsYyCM8RSvfAwCVNsJD10A9voLhRQuYHPIDmay1sBA/casvEvYwMqDZtQIDAQAB";
System.out.println(publicKey.length());
String privatePwd = "lgfishing2018";
String privateAlias = "lgfishing";
String dataStr = "{\"ret\":\"0\",\"ExpireTime\":\"2015/10/28 23:59:59\",\"rettxt\":\"OK\",\"Token\":\"69296128A59798E2D423D3B1A9F766F4\"}'";
/***************************************************************************************************************************************************************************************************************************************/
//客户端公钥加密
String publicEncryptResult = RSA.publicEncrypt(dataStr, RSA.getPublicKey(publicKey));
System.out.println(publicEncryptResult);
// String privateKey = "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAiSo5blJ9-QJ0_QElcy5AaRTq-3oO4lJ8PvIOIt-Xr5SUFODVj3DUbiy6_0bxQYO3NiYHlXPb37UVV3jjlXJsXwIDAQABAkBE0WOJH2hGs93gRl_0vwLf9ffDfkTTdlER_73p70aad3QZRslEkinQH7G5aE_DgBm5m72TCeH-PD2FZ2lwtavBAiEAvnRown5Lpqbl0tN_OUxr_e1u9d_-8dNL_JEETO7BZCECIQC4XtY-18j0bVVLxaXPjKQ00D59yntwObihDNyRK0nAfwIgHPHEGgrnpGQo-Wl7JFIg925mNqfcLxRVsAS6CpcefQECIQCUsLdsmy6QIhTmNRJSXoSXq1KatE_05DhIekzwLs8eFQIgfMawMiu52ZxBI5_pZ7ancQZ6Dsxl45utFqJShzV1pio";
//// String publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIkqOW5SffkCdP0BJXMuQGkU6vt6DuJSfD7yDiLfl6-UlBTg1Y9w1G4suv9G8UGDtzYmB5Vz29-1FVd445VybF8CAwEAAQ";
// String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCX9uSsfJeIDIPzxCtwwFh5vrIKar69i3DPUTDEiKPRdtmADa8Ls6KAsPVpzgtQYoYVpYBoMbBtp0cGRoQULO83NWIAhmsU2cvd0nmGlB2xPRz+uGYW1rsYyCM8RSvfAwCVNsJD10A9voLhRQuYHPIDmay1sBA/casvEvYwMqDZtQIDAQAB";
//
// String privatePwd = "lgfishing2018";
// String privateAlias = "lgfishing";
//
// String dataStr = "{\"ret\":\"0\",\"ExpireTime\":\"2015/10/28 23:59:59\",\"rettxt\":\"OK\",\"Token\":\"69296128A59798E2D423D3B1A9F766F4\"}'";
//
///***************************************************************************************************************************************************************************************************************************************/
// //客户端公钥加密
// String publicEncryptResult = RSA.publicEncrypt(dataStr, RSA.getPublicKey(publicKey));
// System.out.println(publicEncryptResult);
//服务器私钥解密
String privateDecryptResult = RSA.privateDecrypt(publicEncryptResult, RSA.getPrivateKey(privateKey));
System.out.println(privateDecryptResult);
// String privateDecryptResult = RSA.privateDecrypt(publicEncryptResult, RSA.getPrivateKey(privateKey));
// System.out.println(privateDecryptResult);
/***************************************************************************************************************************************************************************************************************************************/
//服务器端私钥加密
String privateEncryptResult = RSA.privateEncrypt(dataStr, RSA.getPrivateKey(privateKey));
System.out.println(privateEncryptResult);
//客户端公钥解密
String publicDecryptResult = RSA.publicDecrypt(privateEncryptResult, RSA.getPublicKey(publicKey));
System.out.println(publicDecryptResult);
System.out.println(Base64.getEncoder().encodeToString(RSA.getPublicKey(publicKey).getEncoded()));
// //服务器端私钥加密
// String privateEncryptResult = RSA.privateEncrypt(dataStr, RSA.getPrivateKey(privateKey));
// System.out.println(privateEncryptResult);
//
// //客户端公钥解密
// String publicDecryptResult = RSA.publicDecrypt(privateEncryptResult, RSA.getPublicKey(publicKey));
// System.out.println(publicDecryptResult);
//
// System.out.println(Base64.getEncoder().encodeToString(RSA.getPublicKey(publicKey).getEncoded()));
}
}

View File

@ -10,9 +10,9 @@ import java.util.Enumeration;
public class CoverToPfx {
public static final String PKCS12 = "PKCS12";
public static final String JKS = "JKS";
public static final String PFX_KEYSTORE_FILE = "D:/idea_work/yexuejc/yexuejc-springboot/yexuejc-springboot-base/src/test/resources/lgfishing2.pfx";
public static final String PFX_KEYSTORE_FILE = "D:/idea_work/yexuejc/yexuejc-springboot/yexuejc-springboot-base/src/test/resources/lgfishing.pfx";
public static final String KEYSTORE_PASSWORD = "lgfishing2018";
public static final String JKS_KEYSTORE_FILE = "D:/idea_work/yexuejc/yexuejc-springboot/yexuejc-springboot-base/src/test/resources/lgfishing2.keystore";
public static final String JKS_KEYSTORE_FILE = "D:/idea_work/yexuejc/yexuejc-springboot/yexuejc-springboot-base/src/test/resources/lgfishing.keystore";
public static void coverTokeyStore() {
try {

View File

@ -0,0 +1,77 @@
package com.yexuejc.springboot.base.test;
import sun.misc.BASE64Encoder;
import java.io.*;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
/**
* 生成公钥工具; http://bijian1013.iteye.com/blog/2339874
* @ClassName: KeyStoreHelper
* @Description:
* @author: maxf
* @date: 2018/6/13 20:50
*/
public class KeyStoreHelper {
public static void main(String[] args) throws Exception {
String privatePath = "D:/testPri.key"; // 准备导出的私钥
String publicPath = "D:/testPub.key"; // 准备导出的公钥
KeyStoreHelper k = new KeyStoreHelper();
String privateKeyPath = k.getClass().getResource("/lgfishing.keystore").getFile().toString();
String publicKeyPath = k.getClass().getResource("/lgfishing.cer").getFile().toString();
// PrivateKey privateKey = getPrivateKeyFromStore(privateKeyPath);
// createKeyFile(privateKey, privatePath);
PublicKey publicKey = getPublicKeyFromCrt(publicKeyPath);
createKeyFile(publicKey, publicPath);
byte[] publicKeyBytes = publicKey.getEncoded();
// byte[] privateKeyBytes = privateKey.getEncoded();
String publicKeyBase64 = new BASE64Encoder().encode(publicKeyBytes);
// String privateKeyBase64 = new BASE64Encoder().encode(privateKeyBytes);
System.out.println("publicKeyBase64.length():" + publicKeyBase64.length());
System.out.println("publicKeyBase64:" + publicKeyBase64);
// System.out.println("privateKeyBase64.length():" + privateKeyBase64.length());
// System.out.println("privateKeyBase64:" + privateKeyBase64);
}
private static PrivateKey getPrivateKeyFromStore(String storePathP) throws Exception {
String alias = "lgfishing"; // KeyTool中生成KeyStore时设置的alias
String storeType = "PKCS12"; // KeyTool中生成KeyStore时设置的storetype
char[] pw = "lgfishing2018".toCharArray(); // KeyTool中生成KeyStore时设置的storepass
String storePath = storePathP; // KeyTool中已生成的KeyStore文件
storeType = null == storeType ? KeyStore.getDefaultType() : storeType;
KeyStore keyStore = KeyStore.getInstance(storeType);
InputStream is = new FileInputStream(storePath);
keyStore.load(is, pw);
// 由密钥库获取密钥的两种方式
// KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias, new KeyStore.PasswordProtection(pw));
// return pkEntry.getPrivateKey();
return (PrivateKey) keyStore.getKey(alias, pw);
}
private static PublicKey getPublicKeyFromCrt(String crtPathP) throws CertificateException, FileNotFoundException {
String crtPath = crtPathP; // KeyTool中已生成的证书文件
CertificateFactory cf = CertificateFactory.getInstance("X.509");
FileInputStream in = new FileInputStream(crtPath);
Certificate crt = cf.generateCertificate(in);
PublicKey publicKey = crt.getPublicKey();
return publicKey;
}
private static void createKeyFile(Object key, String filePath) throws Exception {
FileOutputStream fos = new FileOutputStream(filePath);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(key);
oos.flush();
oos.close();
}
}