liusheng
2024-07-02 0b02577ab12ac83a0530b7e0495b513dd0cdabca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.ruoyi.web.test;
 
import com.ruoyi.web.task.PhoneTask;
import org.junit.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
 
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
 
//@SpringBootTest
//@RunWith(SpringRunner.class)
public class MQTest {
    @Autowired
    private RabbitTemplate rabbitTemplate;
 
    @Test
    public void testSend() {
        try {
 
            // 生成RSA密钥对
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
            keyPairGenerator.initialize(2048);
            KeyPair keyPair = keyPairGenerator.generateKeyPair();
 
            // 获取公钥和私钥
            PublicKey publicKey = keyPair.getPublic();
            PrivateKey privateKey = keyPair.getPrivate();
            String publicKeyString = Base64.getEncoder().encodeToString(privateKey.getEncoded());
            System.out.println(publicKeyString);
            // 明文
            String plainText = "Hello, World!";
 
            // 加密
            Cipher encryptCipher = Cipher.getInstance("RSA");
            encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
            byte[] encryptedBytes = encryptCipher.doFinal(plainText.getBytes());
 
            // 将加密后的数据转换为Base64编码的字符串
            String encryptedText = Base64.getEncoder().encodeToString(encryptedBytes);
            System.out.println("加密后的数据:" + encryptedText);
 
            // 解密
            Cipher decryptCipher = Cipher.getInstance("RSA");
            decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
            byte[] decryptedBytes = decryptCipher.doFinal(Base64.getDecoder().decode(encryptedBytes));
 
            // 明文
            String decryptedText = new String(decryptedBytes);
            System.out.println("解密后的数据:" + decryptedText);
        } catch (Exception e) {
 
        }
 
//        String str = "absdf";
//        String c = Character.toUpperCase(str.charAt(0)) + str.substring(1);
//        System.out.println(c);
        "您好,我是浙二医院张医生,您是${name}吗?还是家属?".replaceAll("$$*variable", "AA");
//        Pattern pattern = Pattern.compile("^(?!.*(好|太好)).*$");
//        Matcher matcher = pattern.matcher("睡眠不好");
//        System.out.println(matcher.matches());
        // 创建固定大小的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(10);
//
//        executorService.submit(new PhoneTask());
    }
 
    @Test
    public void testSend22() {
        try {
            byte[] privateKeyBytes = Base64.getDecoder().decode("");
            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(""));
 
            // 解密后的数据
            String decryptedData = new String(decryptedBytes);
            System.out.println("解密后的数据:" + decryptedData);
        } catch (Exception e) {
        }
    }
}