From 78f4e7c416e50c4f21709feda1034cb1047444fd Mon Sep 17 00:00:00 2001 From: liusheng <337615773@qq.com> Date: 星期二, 02 九月 2025 09:53:08 +0800 Subject: [PATCH] 分页处理 --- ruoyi-common/src/main/java/com/ruoyi/common/utils/RSAPublicKeyExample.java | 143 +++++++++++++++++++++++++++++++++-------------- ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java | 18 +++++- 2 files changed, 114 insertions(+), 47 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java b/ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java index 1a2ce25..a523a63 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java @@ -3,13 +3,16 @@ import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.RSAPublicKeyExample; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.common.utils.http.HttpUtils; import com.smartor.domain.ServiceSubtaskDetail; import com.smartor.domain.ThiedInhospInfo; +import com.smartor.service.IHNGatherPatArchiveService; import io.swagger.models.auth.In; import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; @@ -32,6 +35,8 @@ //@SpringBootTest //@RunWith(SpringRunner.class) public class MQTest { + @Autowired + private IHNGatherPatArchiveService ihnGatherPatArchiveService; @Test public void testSend22() { @@ -54,9 +59,16 @@ @Test public void bb() { - String wxCode="{\"code\":\"0\",\"succ\":true}"; - Map<String, Object> map = JSONObject.parseObject(wxCode, Map.class); - System.out.println(map); + Boolean aBoolean = ihnGatherPatArchiveService.hnDataGather(null); + } + + @Test + public void cc() { + RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); + String s = rsaPublicKeyExample.encryptedData("1012320966", "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALQzqW1EIXBKGMu+2oEYSB5gM7Ox/ihyYTeeoE0yPX1qtt4++5yNOeTBVd6EEM4iKzVEzWj6REIWVwaSNPn/SvUCAwEAAQ=="); + System.out.println("鍔犲瘑缁撴灉涓猴細" + s); + String s1 = rsaPublicKeyExample.decryptedData(s, "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAtDOpbUQhcEoYy77agRhIHmAzs7H+KHJhN56gTTI9fWq23j77nI055MFV3oQQziIrNUTNaPpEQhZXBpI0+f9K9QIDAQABAkB3n0fcWfrcoMN/FU3VnrnZOEF6CzFNxkgU9P8y36QECWKZ9JhYQkNpKrMC9oXlN3VSaRigV7B+L/I/a0Rs1W+tAiEA4jx7xcXJ4y4BNwAmVHt6NNiEkzIwWnwC/0qsEu8NsOsCIQDL6MMn1D2uznC6OuOWpxDCkBh1JL1NzZTZeH2G+hj7nwIgKGAC9tjFnvWm4dn0/T7MIIJDpsFeP8fCAS2iZ/6hwuECIAS/eLvWr1EAsZNEh8QcQ8GkBU3E+ztyjAK8UX/xFt/VAiBf79/1tDErX4/DChecM8w3c3DhbBcjuE3fHZn7p6/UKg=="); + System.out.println("瑙e瘑缁撴灉涓猴細"+s1); } public void aa(MultipartFile file) throws IOException { 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 196de03..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.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"); + 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.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; + // 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