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.
53 lines
2.0 KiB
53 lines
2.0 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.PostMapping; |
|
import org.springframework.web.bind.annotation.RequestBody; |
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
import java.io.IOException; |
|
import java.util.Map; |
|
|
|
@RestController |
|
@RequestMapping("/transmission") |
|
public class TransmissionController { |
|
|
|
@Autowired |
|
private TransmissionService transmissionService; |
|
|
|
@PostMapping("/encrypt/aes") |
|
private String aesEncrypt(@RequestBody Map<String, Object> params) throws Exception { |
|
String plainText = (String) params.get("text"); |
|
String key = (String) params.get("key"); |
|
return transmissionService.aesEncrypt(filter(plainText), filter(key)); |
|
} |
|
|
|
@PostMapping("/decrypt/aes") |
|
private String aesDecrypt(@RequestBody Map<String, Object> params) throws Exception { |
|
String cipherText = (String) params.get("text"); |
|
String key = (String) params.get("key"); |
|
return transmissionService.aesDecrypt(filter(cipherText), filter(key)); |
|
} |
|
|
|
@PostMapping("/encrypt/sm4") |
|
private String sm4Encrypt(@RequestBody Map<String, Object> params) throws Exception { |
|
String plainText = (String) params.get("text"); |
|
String key = (String) params.get("key"); |
|
return transmissionService.sm4Encrypt(filter(plainText), filter(key)); |
|
} |
|
|
|
@PostMapping("/decrypt/sm4") |
|
private String sm4Decrypt(@RequestBody Map<String, Object> params) throws Exception { |
|
String cipherText = (String) params.get("text"); |
|
String key = (String) params.get("key"); |
|
return transmissionService.sm4Decrypt(filter(cipherText), filter(key)); |
|
} |
|
|
|
|
|
private String filter(String origin) throws IOException { |
|
return origin; |
|
} |
|
}
|
|
|