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 | 70 +++++++++++++++++++++++++++++++----
1 files changed, 62 insertions(+), 8 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 812ede4..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
@@ -19,6 +19,7 @@
import com.java110.utils.constant.MappingConstant;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.exception.NoAuthorityException;
+import com.java110.utils.util.Base64Convert;
import com.java110.utils.util.StringUtil;
import org.apache.commons.codec.digest.DigestUtils;
@@ -26,17 +27,11 @@
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
-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;
@@ -67,6 +62,64 @@
* 榛樿缂栫爜
*/
private static final String CHARSET = "utf-8";
+
+
+ // 鍔犲瘑
+ 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;
+ }
+ byte[] raw = sKey.getBytes("utf-8");
+ SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
+ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//"绠楁硶/妯″紡/琛ョ爜鏂瑰紡"
+ cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
+ 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) {
+ 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;
+ }
+ }
/**
@@ -406,6 +459,7 @@
String newSign = md5(reportDataHeaderDto.getTranId() + reportDataHeaderDto.getReqTime() + reportDataDto.getReportDataBodyDto().toJSONString() + code).toLowerCase();
reportDataHeaderDto.setSign(newSign);
}
+
/**
* 鍔犺浇鍏挜
*
--
Gitblit v1.8.0