| | |
| | | package com.ruoyi.web.test; |
| | | |
| | | import com.ruoyi.web.task.PhoneTask; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.file.FileUploadUtils; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.smartor.domain.ServiceSubtaskDetail; |
| | | import com.smartor.domain.ThiedInhospInfo; |
| | | import io.swagger.models.auth.In; |
| | | import org.junit.Test; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.mock.web.MockMultipartFile; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | 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; |
| | | import java.io.*; |
| | | import java.math.BigInteger; |
| | | import java.nio.file.Files; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static org.eclipse.jetty.http.HttpGenerator.CHUNK_SIZE; |
| | | |
| | | //@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() { |
| | | // uploadFileInChunks(new File("C:\\Users\\86176\\Desktop\\19-图解es内部基于_version乐观锁控制.mp4")); |
| | | File file = new File("C:\\Users\\86176\\Desktop\\19-图解es内部基于_version乐观锁控制.mp4"); |
| | | |
| | | |
| | | FileInputStream input = null; |
| | | 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) { |
| | | input = new FileInputStream(new File("C:\\Users\\86176\\Desktop\\19-图解es内部基于_version乐观锁控制.mp4")); |
| | | MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(), "application/octet-stream", input); |
| | | aa(multipartFile); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Test |
| | | public void bb() { |
| | | |
| | | } |
| | | |
| | | public void aa(MultipartFile file) throws IOException { |
| | | System.out.println("开始Aa:" + System.currentTimeMillis()); |
| | | String filePath = "D:\\test\\Ab"; |
| | | // 上传并返回新文件名称 |
| | | String fileName = FileUploadUtils.upload(filePath, file); |
| | | System.out.println("结束Aa:" + System.currentTimeMillis()); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |