TestToken.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.mtoken.gm3000;
  2. import com.yumawk.mToken;
  3. import org.junit.Test;
  4. public class TestToken {
  5. @Test
  6. public void TestGetUserName() {
  7. String userName;
  8. mToken token = new mToken();
  9. userName = token.GetUserList();
  10. if (userName == null || userName.isEmpty()) {
  11. System.out.println(token.GetLastError());
  12. }
  13. System.out.println("用户名称:" + userName);
  14. }
  15. @Test
  16. public void TestSignData() {
  17. String userName = "";
  18. String signdata = "";
  19. String cert = "";
  20. //1.初始化组件
  21. mToken token = new mToken();
  22. //2.获取用户列表
  23. userName = token.GetUserList();
  24. if (userName == null || userName.isEmpty()) {
  25. System.out.println(token.GetLastError());
  26. return ;
  27. }
  28. //3.签名数据,为方便演示,这里数据为“Hello"
  29. signdata = token.SignData(userName, "123456", "你好");
  30. //4.导出签名证书,用于验证签名
  31. cert = token.exportCert(userName);
  32. if (signdata == null || signdata.isEmpty()) {
  33. System.out.println(token.GetLastError());
  34. } else {
  35. System.out.println("签名数据:" + signdata);
  36. System.out.println("签名证书:" + cert);
  37. }
  38. }
  39. }