From 4842fb12fcb26c714768dab0e47d7e9012ffa87e Mon Sep 17 00:00:00 2001
From: suerprisePlus <15810472099@163.com>
Date: 星期五, 27 九月 2024 09:56:45 +0800
Subject: [PATCH] 当问到库中不存在的数据时,直接卡死,如问题:查看台湾花莲机场之间的关系、战场环境总结报告

---
 src/main/java/com/yb/helper/RsaHelper.java |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/yb/helper/RsaHelper.java b/src/main/java/com/yb/helper/RsaHelper.java
index b224ca7..79a4dc5 100644
--- a/src/main/java/com/yb/helper/RsaHelper.java
+++ b/src/main/java/com/yb/helper/RsaHelper.java
@@ -3,6 +3,7 @@
 import org.apache.commons.codec.binary.Base64;
 
 import javax.crypto.Cipher;
+import java.io.IOException;
 import java.security.KeyFactory;
 import java.security.interfaces.RSAPublicKey;
 import java.security.spec.X509EncodedKeySpec;
@@ -10,18 +11,24 @@
 public class RsaHelper {
     //    RsA绉橀挜鍔犲瘑
     public static String encrypt(String key, String str) throws Exception {
+        try {
+            byte[] decoded = Base64.decodeBase64(key + "");
+
+            RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
+
+            // RSA鍔犲瘑锛歊SA/ECB/NoPadding
+            Cipher cipher = Cipher.getInstance("RSA");
+            cipher.init(Cipher.ENCRYPT_MODE, pubKey);
+
+            String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes("UTF-8")));
+
+            return outStr;
+        }  catch (IOException e) {
+            System.out.println(e.getMessage());
+            return null;
+        }
         // Base64缂栫爜鐨勫叕閽�
-        byte[] decoded = Base64.decodeBase64(key + "");
 
-        RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
-
-        // RSA鍔犲瘑锛歊SA/ECB/NoPadding
-        Cipher cipher = Cipher.getInstance("RSA");
-        cipher.init(Cipher.ENCRYPT_MODE, pubKey);
-
-        String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes("UTF-8")));
-
-        return outStr;
     }
 
 }

--
Gitblit v1.9.3