package com.mtoken.gm3000;

import com.yumawk.mToken;
import org.junit.Test;

public class TestToken {

    @Test
    public void TestGetUserName() {
        String userName;
        mToken token = new mToken();
        userName = token.GetUserList();
        if (userName == null || userName.isEmpty()) {
            System.out.println(token.GetLastError());
        }
        System.out.println("用户名称：" + userName);
    }

    @Test
    public void TestSignData() {
        String userName = "";
        String signdata = "";
        String cert = "";

        //1.初始化组件
        mToken token = new mToken();

        //2.获取用户列表
        userName = token.GetUserList();
        if (userName == null || userName.isEmpty()) {
            System.out.println(token.GetLastError());
            return ;
        }

        //3.签名数据，为方便演示，这里数据为“Hello"
        signdata = token.SignData(userName, "123456", "你好");

        //4.导出签名证书,用于验证签名
        cert = token.exportCert(userName);
        if (signdata == null || signdata.isEmpty()) {
            System.out.println(token.GetLastError());
        } else {
            System.out.println("签名数据：" + signdata);
            System.out.println("签名证书：" + cert);
        }
    }

}
