提供测试使用的加解密验证工具🔧
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

43 lines
1.6 KiB

package com.fr.password.controller;
import com.fr.password.service.TransmissionService;
import com.fr.password.tool.SecurityToolbox;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
@RestController
@RequestMapping("/transmission")
public class TransmissionController {
@Autowired
private TransmissionService transmissionService;
@RequestMapping("/encrypt/aes")
private String aesEncrypt(@RequestParam String plainText, @RequestParam String key) throws Exception {
return transmissionService.aesEncrypt(filter(plainText), filter(key));
}
@RequestMapping("/decrypt/aes")
private String aesDecrypt(@RequestParam String cipherText, @RequestParam String key) throws Exception {
return transmissionService.aesDecrypt(filter(cipherText),filter(key));
}
@RequestMapping("/encrypt/sm4")
private String sm4Encrypt(@RequestParam String plainText, @RequestParam String key) throws Exception {
return transmissionService.sm4Encrypt(filter(plainText),filter(key));
}
@RequestMapping("/decrypt/sm4")
private String sm4Decrypt(@RequestParam String cipherText, @RequestParam String key) throws Exception {
return transmissionService.sm4Decrypt(filter(cipherText), filter(key));
}
private String filter(String origin) throws IOException {
return new String(SecurityToolbox.getInstance().base642Byte(origin)).trim().replace("\\n","\n");
}
}