From 30cae3cbdea7dfb4d04b564ffd32dca8d70e94f3 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 11 十一月 2024 16:39:37 +0800
Subject: [PATCH] 11

---
 src/main/java/com/se/simu/helper/RsaHelper.java |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/se/simu/helper/RsaHelper.java b/src/main/java/com/se/simu/helper/RsaHelper.java
index c7a70eb..88beabe 100644
--- a/src/main/java/com/se/simu/helper/RsaHelper.java
+++ b/src/main/java/com/se/simu/helper/RsaHelper.java
@@ -137,4 +137,17 @@
 
         return outStr;
     }
+
+    public static String encrypt(String key, String str) throws Exception {
+        byte[] decoded = Base64.decodeBase64(key);
+
+        RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
+
+        Cipher cipher = Cipher.getInstance("RSA");
+        cipher.init(Cipher.ENCRYPT_MODE, pubKey);
+
+        String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes(StandardCharsets.UTF_8)));
+
+        return outStr;
+    }
 }

--
Gitblit v1.9.3