package com.dkl.web.controller.system;

import com.koal.kms.sdk.ed.KmsSdkException;
import com.koal.kms.sdk.ed.KmsUtil;
import com.koal.kms.sdk.ed.Mode;
import com.dkl.web.util.EnciphermentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

@RestController
@RequestMapping("/system/encipherment")
public class EnciphermentController {
    public static final Logger log = LoggerFactory.getLogger(EnciphermentController.class);

    @Autowired
    static EnciphermentUtil enciphermentUtil;
    /**
     * 数据加密
     * originData 待加密数据
     */
    @GetMapping(value = "/kmsEncrypt/{originData}")
    public  String kmsEncrypt(@PathVariable String originData) throws KmsSdkException {

        return  enciphermentUtil.kmsEncrypt(originData);

    }

    /**
     * 数据解密
     * encryptData 加密后的数据
     */
    @GetMapping(value = "/kmsDencrypt/{encryptData}")
    public  String kmsDencrypt(@PathVariable String encryptData) throws KmsSdkException {
        return  enciphermentUtil.kmsDencrypt(encryptData);

    }
}
