From b28126cc4331998f4debc0e27081a44f81009b3c Mon Sep 17 00:00:00 2001
From: sinake <sinake1@qq.com>
Date: 星期一, 15 九月 2025 10:55:41 +0800
Subject: [PATCH] 出院过率条件改成inhospstate=1
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/RSAPublicKeyExample.java | 143 +++++++++++++++++++++++++++++++++--------------
1 files changed, 99 insertions(+), 44 deletions(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/RSAPublicKeyExample.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/RSAPublicKeyExample.java
index 2159f6d..1496ae7 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/RSAPublicKeyExample.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/RSAPublicKeyExample.java
@@ -19,37 +19,71 @@
@Component
public class RSAPublicKeyExample {
-
- /**
- * 鏁版嵁瑙e瘑
- *
- * @param encryptedData
- * @return
- */
- public String decryptedData(String encryptedData, String pri_key) {
- String privateKeyString = "绉侀挜鐨凚ase64缂栫爜瀛楃涓�"; // 鍚庣绉侀挜鐨凚ase64缂栫爜瀛楃涓�
-
- try {
- // 灏嗙閽ase64缂栫爜瀛楃涓茶浆鎹负PrivateKey瀵硅薄
- byte[] privateKeyBytes = Base64.getDecoder().decode(pri_key);
- PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
- KeyFactory keyFactory = KeyFactory.getInstance("RSA");
- PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
-
- // 浣跨敤绉侀挜瑙e瘑鏁版嵁
- Cipher decryptCipher = Cipher.getInstance("RSA");
- decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
- byte[] decryptedBytes = decryptCipher.doFinal(Base64.getDecoder().decode(encryptedData));
-
- // 瑙e瘑鍚庣殑鏁版嵁
- String decryptedData = new String(decryptedBytes);
- System.out.println("瑙e瘑鍚庣殑鏁版嵁锛�" + decryptedData);
- return decryptedData;
- } catch (Exception e) {
- log.error("瑙e瘑鎶ラ敊浜�:{}", e.getMessage());
- }
- return null;
- }
+//
+// /**
+// * 鏁版嵁瑙e瘑
+// *
+// * @param encryptedData
+// * @return
+// */
+// public String decryptedData(String encryptedData, String pri_key) {
+// String privateKeyString = "绉侀挜鐨凚ase64缂栫爜瀛楃涓�"; // 鍚庣绉侀挜鐨凚ase64缂栫爜瀛楃涓�
+//
+// try {
+// // 灏嗙閽ase64缂栫爜瀛楃涓茶浆鎹负PrivateKey瀵硅薄
+// byte[] privateKeyBytes = Base64.getDecoder().decode(pri_key);
+// PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
+// KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+// PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
+//
+// // 浣跨敤绉侀挜瑙e瘑鏁版嵁
+// Cipher decryptCipher = Cipher.getInstance("RSA");
+// decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
+// byte[] decryptedBytes = decryptCipher.doFinal(Base64.getDecoder().decode(encryptedData));
+//
+// // 瑙e瘑鍚庣殑鏁版嵁
+// String decryptedData = new String(decryptedBytes);
+// System.out.println("瑙e瘑鍚庣殑鏁版嵁锛�" + decryptedData);
+// return decryptedData;
+// } catch (Exception e) {
+// log.error("瑙e瘑鎶ラ敊浜�:{}", e.getMessage());
+// }
+// return null;
+// }
+//
+// /**
+// * 瑕佸姞瀵嗙殑鏄庢枃鏁版嵁
+// *
+// * @param plainText
+// * @return
+// */
+// public String encryptedData(String plainText, String pub_key) {
+// log.info("闇�瑕佸姞瀵嗙殑鏁版嵁锛歿}", plainText);
+// try {
+//
+// byte[] publicKeyBytes = Base64.getDecoder().decode(pub_key);
+// X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKeyBytes);
+// KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+// PublicKey publicKey = keyFactory.generatePublic(keySpec);
+//
+// // 浣跨敤鍏挜鍔犲瘑鏁版嵁
+// Cipher encryptCipher = Cipher.getInstance("RSA");
+// encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
+// byte[] encryptedBytes = encryptCipher.doFinal(plainText.getBytes());
+//
+// // 灏嗗姞瀵嗗悗鐨勬暟鎹浆鎹负Base64缂栫爜鐨勫瓧绗︿覆
+// String encryptedText = Base64.getEncoder().encodeToString(encryptedBytes);
+// log.info("Base64鍔犲瘑鍚庣殑鏁版嵁锛歿}", encryptedText);
+// encryptedText = URLEncoder.encode(encryptedText, StandardCharsets.UTF_8.toString());
+// log.info("URLEncoder缂栫爜鍚庣殑鏁版嵁锛歿}", encryptedText);
+// String decodedString = URLDecoder.decode(encryptedText, "UTF-8");
+// log.info("URLEncoder瑙g爜鍚庣殑鏁版嵁锛歿}", decodedString);
+// return encryptedText;
+// } catch (Exception e) {
+// log.error("鍔犲瘑澶辫触浜�:{}", e.getMessage());
+// }
+// return null;
+// }
/**
* 瑕佸姞瀵嗙殑鏄庢枃鏁版嵁
@@ -58,29 +92,50 @@
* @return
*/
public String encryptedData(String plainText, String pub_key) {
- log.error("闇�瑕佸姞瀵嗙殑鏁版嵁锛歿}", plainText);
try {
-
byte[] publicKeyBytes = Base64.getDecoder().decode(pub_key);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKeyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey publicKey = keyFactory.generatePublic(keySpec);
// 浣跨敤鍏挜鍔犲瘑鏁版嵁
- Cipher encryptCipher = Cipher.getInstance("RSA");
+ Cipher encryptCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
- byte[] encryptedBytes = encryptCipher.doFinal(plainText.getBytes());
+ byte[] encryptedBytes = encryptCipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));
- // 灏嗗姞瀵嗗悗鐨勬暟鎹浆鎹负Base64缂栫爜鐨勫瓧绗︿覆
- String encryptedText = Base64.getEncoder().encodeToString(encryptedBytes);
- log.error("Base64鍔犲瘑鍚庣殑鏁版嵁锛歿}", encryptedText);
- encryptedText = URLEncoder.encode(encryptedText, StandardCharsets.UTF_8.toString());
- log.error("URLEncoder缂栫爜鍚庣殑鏁版嵁锛歿}", encryptedText);
- String decodedString = URLDecoder.decode(encryptedText, "UTF-8");
- log.error("URLEncoder瑙g爜鍚庣殑鏁版嵁锛歿}", decodedString);
- return encryptedText;
+ // URL Safe Base64 缂栫爜
+ return Base64.getUrlEncoder().encodeToString(encryptedBytes);
} catch (Exception e) {
- log.error("鍔犲瘑澶辫触浜�:{}", e.getMessage());
+ log.error("鍔犲瘑澶辫触: {}", e.getMessage());
+ }
+ return null;
+ }
+
+ /**
+ * 鏁版嵁瑙e瘑
+ *
+ * @param encryptedData
+ * @return
+ */
+ public String decryptedData(String encryptedData, String pri_key) {
+ try {
+ // 灏嗙閽ase64缂栫爜瀛楃涓茶浆鎹负PrivateKey瀵硅薄
+ byte[] privateKeyBytes = Base64.getDecoder().decode(pri_key);
+ PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
+ KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+ PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
+
+ // URL Safe Base64 瑙g爜
+ byte[] cipherBytes = Base64.getUrlDecoder().decode(encryptedData);
+
+ // 浣跨敤绉侀挜瑙e瘑鏁版嵁
+ Cipher decryptCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
+ decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
+ byte[] decryptedBytes = decryptCipher.doFinal(cipherBytes);
+
+ return new String(decryptedBytes, StandardCharsets.UTF_8);
+ } catch (Exception e) {
+ log.error("瑙e瘑澶辫触: {}", e.getMessage());
}
return null;
}
--
Gitblit v1.9.3