liusheng
4 天以前 78f4e7c416e50c4f21709feda1034cb1047444fd
分页处理
已修改2个文件
161 ■■■■ 文件已修改
ruoyi-admin/src/main/java/com/ruoyi/web/test/MQTest.java 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-common/src/main/java/com/ruoyi/common/utils/RSAPublicKeyExample.java 143 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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("解密结果为:"+s1);
    }
    public void aa(MultipartFile file) throws IOException {
ruoyi-common/src/main/java/com/ruoyi/common/utils/RSAPublicKeyExample.java
@@ -19,37 +19,71 @@
@Component
public class RSAPublicKeyExample {
    /**
     * 数据解密
     *
     * @param encryptedData
     * @return
     */
    public String decryptedData(String encryptedData, String pri_key) {
        String privateKeyString = "私钥的Base64编码字符串"; // 后端私钥的Base64编码字符串
        try {
            // 将私钥Base64编码字符串转换为PrivateKey对象
            byte[] privateKeyBytes = Base64.getDecoder().decode(pri_key);
            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
            // 使用私钥解密数据
            Cipher decryptCipher = Cipher.getInstance("RSA");
            decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
            byte[] decryptedBytes = decryptCipher.doFinal(Base64.getDecoder().decode(encryptedData));
            // 解密后的数据
            String decryptedData = new String(decryptedBytes);
            System.out.println("解密后的数据:" + decryptedData);
            return decryptedData;
        } catch (Exception e) {
            log.error("解密报错了:{}", e.getMessage());
        }
        return null;
    }
//
//    /**
//     * 数据解密
//     *
//     * @param encryptedData
//     * @return
//     */
//    public String decryptedData(String encryptedData, String pri_key) {
//        String privateKeyString = "私钥的Base64编码字符串"; // 后端私钥的Base64编码字符串
//
//        try {
//            // 将私钥Base64编码字符串转换为PrivateKey对象
//            byte[] privateKeyBytes = Base64.getDecoder().decode(pri_key);
//            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
//            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//            PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
//
//            // 使用私钥解密数据
//            Cipher decryptCipher = Cipher.getInstance("RSA");
//            decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
//            byte[] decryptedBytes = decryptCipher.doFinal(Base64.getDecoder().decode(encryptedData));
//
//            // 解密后的数据
//            String decryptedData = new String(decryptedBytes);
//            System.out.println("解密后的数据:" + decryptedData);
//            return decryptedData;
//        } catch (Exception e) {
//            log.error("解密报错了:{}", 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解码后的数据:{}", 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解码后的数据:{}", decodedString);
            return encryptedText;
            // URL Safe Base64 编码
            return Base64.getUrlEncoder().encodeToString(encryptedBytes);
        } catch (Exception e) {
            log.error("加密失败了:{}", e.getMessage());
            log.error("加密失败: {}", e.getMessage());
        }
        return null;
    }
    /**
     * 数据解密
     *
     * @param encryptedData
     * @return
     */
    public String decryptedData(String encryptedData, String pri_key) {
        try {
            // 将私钥Base64编码字符串转换为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 解码
            byte[] cipherBytes = Base64.getUrlDecoder().decode(encryptedData);
            // 使用私钥解密数据
            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.getMessage());
        }
        return null;
    }