From d31920a1233ab14cdd5e33756bb1b0e3ed235e66 Mon Sep 17 00:00:00 2001
From: 1098226878 <1098226878@qq.com>
Date: 星期三, 08 九月 2021 12:39:48 +0800
Subject: [PATCH] Merge branch 'master' of http://git.homecommunity.cn/supervip/MicroCommunity

---
 java110-core/src/main/java/com/java110/core/factory/AuthenticationFactory.java |   77 ++++++++++++++++++--------------------
 1 files changed, 37 insertions(+), 40 deletions(-)

diff --git a/java110-core/src/main/java/com/java110/core/factory/AuthenticationFactory.java b/java110-core/src/main/java/com/java110/core/factory/AuthenticationFactory.java
index 6aa8d5e..70cad92 100755
--- a/java110-core/src/main/java/com/java110/core/factory/AuthenticationFactory.java
+++ b/java110-core/src/main/java/com/java110/core/factory/AuthenticationFactory.java
@@ -22,7 +22,6 @@
 import com.java110.utils.util.Base64Convert;
 import com.java110.utils.util.StringUtil;
 import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.logging.log4j.util.Base64Util;
 
 import javax.crypto.Cipher;
 import javax.crypto.SecretKeyFactory;
@@ -32,15 +31,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.security.InvalidParameterException;
-import java.security.Key;
-import java.security.KeyFactory;
-import java.security.KeyPair;
-import java.security.KeyPairGenerator;
-import java.security.MessageDigest;
-import java.security.PrivateKey;
-import java.security.PublicKey;
+import java.security.*;
 import java.security.spec.PKCS8EncodedKeySpec;
 import java.security.spec.X509EncodedKeySpec;
 import java.util.Base64;
@@ -73,8 +64,9 @@
     private static final String CHARSET = "utf-8";
 
 
-        // 鍔犲瘑
-        public static String AesEncrypt(String sSrc, String sKey) throws Exception {
+    // 鍔犲瘑
+    public static String AesEncrypt(String sSrc, String sKey) {
+        try {
             if (sKey == null) {
                 System.out.print("Key涓虹┖null");
                 return null;
@@ -91,39 +83,43 @@
             byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
 
             return Base64Convert.byteToBase64(encrypted);//姝ゅ浣跨敤BASE64鍋氳浆鐮佸姛鑳斤紝鍚屾椂鑳借捣鍒�2娆″姞瀵嗙殑浣滅敤銆�
+        } catch (Exception e) {
+            e.printStackTrace();
         }
+        return "";
+    }
 
-        // 瑙e瘑
-        public static String AesDecrypt(String sSrc, String sKey) throws Exception {
-            try {
-                // 鍒ゆ柇Key鏄惁姝g‘
-                if (sKey == null) {
-                    System.out.print("Key涓虹┖null");
-                    return null;
-                }
-                // 鍒ゆ柇Key鏄惁涓�16浣�
-                if (sKey.length() != 16) {
-                    System.out.print("Key闀垮害涓嶆槸16浣�");
-                    return null;
-                }
-                byte[] raw = sKey.getBytes("utf-8");
-                SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
-                Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
-                cipher.init(Cipher.DECRYPT_MODE, skeySpec);
-                byte[] encrypted1 = Base64Convert.base64ToByte(sSrc);//鍏堢敤base64瑙e瘑
-                try {
-                    byte[] original = cipher.doFinal(encrypted1);
-                    String originalString = new String(original,"utf-8");
-                    return originalString;
-                } catch (Exception e) {
-                    System.out.println(e.toString());
-                    return null;
-                }
-            } catch (Exception ex) {
-                System.out.println(ex.toString());
+    // 瑙e瘑
+    public static String AesDecrypt(String sSrc, String sKey) {
+        try {
+            // 鍒ゆ柇Key鏄惁姝g‘
+            if (sKey == null) {
+                System.out.print("Key涓虹┖null");
                 return null;
             }
+            // 鍒ゆ柇Key鏄惁涓�16浣�
+            if (sKey.length() != 16) {
+                System.out.print("Key闀垮害涓嶆槸16浣�");
+                return null;
+            }
+            byte[] raw = sKey.getBytes("utf-8");
+            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
+            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+            cipher.init(Cipher.DECRYPT_MODE, skeySpec);
+            byte[] encrypted1 = Base64Convert.base64ToByte(sSrc);//鍏堢敤base64瑙e瘑
+            try {
+                byte[] original = cipher.doFinal(encrypted1);
+                String originalString = new String(original, "utf-8");
+                return originalString;
+            } catch (Exception e) {
+                System.out.println(e.toString());
+                return null;
+            }
+        } catch (Exception ex) {
+            System.out.println(ex.toString());
+            return null;
         }
+    }
 
 
     /**
@@ -463,6 +459,7 @@
         String newSign = md5(reportDataHeaderDto.getTranId() + reportDataHeaderDto.getReqTime() + reportDataDto.getReportDataBodyDto().toJSONString() + code).toLowerCase();
         reportDataHeaderDto.setSign(newSign);
     }
+
     /**
      * 鍔犺浇鍏挜
      *

--
Gitblit v1.8.0