package cn.unitid.matrix.pkiservice.test.ces;

import cn.unitid.matrix.pkiservice.sdk.ApiException;
import cn.unitid.matrix.pkiservice.sdk.PkiClient;
import cn.unitid.matrix.pkiservice.sdk.PkiOkhttpClient;
import cn.unitid.matrix.pkiservice.sdk.ces.request.HmacRequest;
import cn.unitid.matrix.pkiservice.sdk.ces.response.HmacResponse;
import cn.unitid.matrix.pkiservice.sdk.consts.DataType;

public class HmacTest {

    public static void main(String[] args) {

        // 提供的URL
        String url = "http://172.16.6.102:9200";

        // 您的appKey
        String appKey = "yQHIS771zS";

        // 您的appSecret
        String appSecret = "7Vz6HI9Xo833cUJmXzzXrgSwasEwkYOn";

        // 原客户端
        PkiClient pkiClient = new PkiOkhttpClient(url, appKey, appSecret);


        HmacRequest request = new HmacRequest();

        request.setData("123");

        request.setDataType(DataType.ORIGINAL);

        request.setHmacAlgorithm("HMAC-SM3");

        request.setDigestDataType(DataType.BASE64);

        request.setHmacKey("123");

        try {
            HmacResponse response = pkiClient.execute(request);
            // 后续业务
            if (response.isSuccess()) {
                System.out.println("成功：" + response.getResult());
            } else {
                System.out.println("失败：" + response.getBody());
            }
        } catch (ApiException e) {
            e.printStackTrace();
        }

    }
}
