diff --git a/UPDATE.md b/UPDATE.md index d91fa37..53ac81e 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -1,8 +1,16 @@ uselaw-base 更新内容 ------------------- +#### version :1.0.10 +**time:2018年6月14日22:31:18**
+**branch:** master
+**update:**
+1. 更新springboot-base:1.1.4依赖 +2. 统一编码:UTF-8 +# + #### version :1.0.9 -**time:**
+**time:2018年6月2日12:17:18**
**branch:** master
**update:**
1. 更新base依赖 diff --git a/pom.xml b/pom.xml index 31987f1..f49e5b5 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.yexuejc.springboot yexuejc-springboot-parent - 1.0.9 + 1.0.10 pom ${project.artifactId} @@ -35,7 +35,7 @@ 1.2.0 3.4.2 - 1.1.3 + 1.1.4 0.7.0 1.1.46 1.10 @@ -218,6 +218,15 @@ ${project.artifactId} + + org.apache.maven.plugins + maven-compiler-plugin + + UTF-8 + ${java.version} + ${java.version} + + org.apache.maven.plugins @@ -253,6 +262,7 @@ maven-assembly-plugin ${project.artifactId}-${project.version} + UTF-8 diff --git a/yexuejc-springboot-base/pom.xml b/yexuejc-springboot-base/pom.xml index 7ca895f..4004b03 100644 --- a/yexuejc-springboot-base/pom.xml +++ b/yexuejc-springboot-base/pom.xml @@ -9,7 +9,7 @@ com.yexuejc.springboot yexuejc-springboot-parent - 1.0.9 + 1.0.10 diff --git a/yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/autoconfigure/WebAutoConfiguration.java b/yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/autoconfigure/WebAutoConfiguration.java index 845aa7f..f9a07ef 100644 --- a/yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/autoconfigure/WebAutoConfiguration.java +++ b/yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/autoconfigure/WebAutoConfiguration.java @@ -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 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); } } } diff --git a/yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/ApplicationTest.java b/yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/ApplicationTest.java index e6d878f..9a1e3bb 100644 --- a/yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/ApplicationTest.java +++ b/yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/ApplicationTest.java @@ -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())); } } diff --git a/yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/CoverToPfx.java b/yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/CoverToPfx.java index bb04605..3c3b3eb 100644 --- a/yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/CoverToPfx.java +++ b/yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/CoverToPfx.java @@ -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 { diff --git a/yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/KeyStoreHelper.java b/yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/KeyStoreHelper.java new file mode 100644 index 0000000..c9318e4 --- /dev/null +++ b/yexuejc-springboot-base/src/test/java/com/yexuejc/springboot/base/test/KeyStoreHelper.java @@ -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(); + } +} \ No newline at end of file