118 lines
3.0 KiB
Java
118 lines
3.0 KiB
Java
package com.sunyard.chsm.controller;
|
|
|
|
import com.sunyard.chsm.auth.AuthCode;
|
|
import com.sunyard.chsm.constant.AuthCodeConst;
|
|
import com.sunyard.chsm.model.R;
|
|
import com.sunyard.chsm.param.SymDecryptReq;
|
|
import com.sunyard.chsm.param.SymDecryptResp;
|
|
import com.sunyard.chsm.param.SymEncryptReq;
|
|
import com.sunyard.chsm.param.SymEncryptResp;
|
|
import com.sunyard.chsm.param.SymHmacCheckReq;
|
|
import com.sunyard.chsm.param.SymHmacReq;
|
|
import com.sunyard.chsm.param.SymHmacResp;
|
|
import com.sunyard.chsm.param.SymMacCheckReq;
|
|
import com.sunyard.chsm.param.SymMacReq;
|
|
import com.sunyard.chsm.param.SymMacResp;
|
|
import com.sunyard.chsm.param.VerifyResp;
|
|
import com.sunyard.chsm.service.SymKeyService;
|
|
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 javax.validation.Valid;
|
|
|
|
/**
|
|
* 对称运算类接口
|
|
*
|
|
* @author liulu
|
|
* @since 2024/12/17
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/sym")
|
|
public class SymKeyController {
|
|
|
|
@Autowired
|
|
private SymKeyService symKeyService;
|
|
|
|
/**
|
|
* 对称加密
|
|
*
|
|
* @param req
|
|
* @return
|
|
*/
|
|
@PostMapping("/encrypt")
|
|
@AuthCode(AuthCodeConst.sym_enc)
|
|
public R<SymEncryptResp> encrypt(@Valid @RequestBody SymEncryptReq req) {
|
|
SymEncryptResp resp = symKeyService.encrypt(req);
|
|
return R.data(resp);
|
|
}
|
|
|
|
/**
|
|
* 对称解密
|
|
*
|
|
* @param req
|
|
* @return
|
|
*/
|
|
@PostMapping("/decrypt")
|
|
@AuthCode(AuthCodeConst.sym_dec)
|
|
public R<SymDecryptResp> decrypt(@Valid @RequestBody SymDecryptReq req) {
|
|
SymDecryptResp resp = symKeyService.decrypt(req);
|
|
return R.data(resp);
|
|
}
|
|
|
|
/**
|
|
* 计算Hmac
|
|
*
|
|
* @param req
|
|
* @return
|
|
*/
|
|
@PostMapping("/hmac")
|
|
@AuthCode(AuthCodeConst.cal_hmac)
|
|
public R<SymHmacResp> hmac(@Valid @RequestBody SymHmacReq req) {
|
|
SymHmacResp resp = symKeyService.hmac(req);
|
|
return R.data(resp);
|
|
}
|
|
|
|
/**
|
|
* 验证Hmac
|
|
*
|
|
* @param req
|
|
* @return
|
|
*/
|
|
@PostMapping("/hmac/check")
|
|
@AuthCode(AuthCodeConst.check_hmac)
|
|
public R<VerifyResp> macCheck(@Valid @RequestBody SymHmacCheckReq req) {
|
|
VerifyResp resp = symKeyService.hmacCheck(req);
|
|
return R.data(resp);
|
|
}
|
|
|
|
/**
|
|
* 计算Hmac
|
|
*
|
|
* @param req
|
|
* @return
|
|
*/
|
|
@PostMapping("/mac")
|
|
@AuthCode(AuthCodeConst.cal_mac)
|
|
public R<SymMacResp> mac(@Valid @RequestBody SymMacReq req) {
|
|
SymMacResp resp = symKeyService.mac(req);
|
|
return R.data(resp);
|
|
}
|
|
|
|
/**
|
|
* 验证Hmac
|
|
*
|
|
* @param req
|
|
* @return
|
|
*/
|
|
@PostMapping("/mac/check")
|
|
@AuthCode(AuthCodeConst.check_mac)
|
|
public R<VerifyResp> macCheck(@Valid @RequestBody SymMacCheckReq req) {
|
|
VerifyResp resp = symKeyService.macCheck(req);
|
|
return R.data(resp);
|
|
}
|
|
|
|
}
|