From 3d8ec5c23ef49d0908195c8b5b892920a46aaa8c Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 30 五月 2023 11:42: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 | 89 ++++++++++++++++++++++----------------------
1 files changed, 44 insertions(+), 45 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..cd2b901 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;
@@ -54,7 +45,9 @@
*/
public class AuthenticationFactory {
- private final static String PASSWD_SALT = "hc@java110";
+ public final static String PASSWD_SALT = "hc@java110";
+
+ public final static String AES_KEY = "whoisyourdaddy!!";
/**
* 鍋忕Щ鍙橀噺锛屽浐瀹氬崰8浣嶅瓧鑺�
*/
@@ -73,17 +66,18 @@
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;
}
// 鍒ゆ柇Key鏄惁涓�16浣�
- if (sKey.length() != 16) {
- System.out.print("Key闀垮害涓嶆槸16浣�");
- return null;
- }
+// 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");//"绠楁硶/妯″紡/琛ョ爜鏂瑰紡"
@@ -91,39 +85,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 +461,7 @@
String newSign = md5(reportDataHeaderDto.getTranId() + reportDataHeaderDto.getReqTime() + reportDataDto.getReportDataBodyDto().toJSONString() + code).toLowerCase();
reportDataHeaderDto.setSign(newSign);
}
+
/**
* 鍔犺浇鍏挜
*
--
Gitblit v1.8.0