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) { } } }