加密狗的管理层API(C#代码).txt 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Runtime.InteropServices;
  5. //class NT88API
  6. //{
  7. ////查找加密锁
  8. // [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  9. // public static extern int NTFindFirst(string NTCode);
  10. ////查询硬件ID
  11. // [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  12. // public static extern int NTGetHardwareID(StringBuilder hardwareID);
  13. ////登录加密锁
  14. // [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  15. // public static extern int NTLogin(string NTpassword);
  16. ////存储区数据读取
  17. // [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  18. // public static extern int NTRead(int address, int Length, byte[] pData);
  19. ////存储区数据写入
  20. // [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  21. // public static extern int NTWrite(int address, int Length, byte[] pData);
  22. ////3DES解密
  23. // [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  24. // public static extern int NT3DESCBCDecrypt(byte[] vi, byte[] pDataBuffer, int Length);
  25. ////3DES加密
  26. // [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  27. // public static extern int NT3DESCBCEncrypt(byte[] vi, byte[] pDataBuffer, int Length);
  28. ////验证许可证
  29. // [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  30. // public static extern int NTCheckLicense(int licenseCode);
  31. ////登出加密锁
  32. // [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
  33. // public static extern int NTLogout();
  34. // #region 管理员API
  35. ////验证管理员密码
  36. // [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  37. // public static extern int NTCheckSuperPin(string superPin);
  38. // #endregion
  39. //}
  40. class NT88API
  41. {
  42. #region 管理员用法
  43. //查找所有加密锁,只有找到加密锁才能其他操作,NTFindAll必须第一个执行
  44. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  45. public static extern int NTFindAll(int[] NTHandle, int[] nKeyNum);
  46. /// <summary>
  47. /// 获取加密锁硬件属性
  48. /// </summary>
  49. /// <param name="NTHandle">加密锁handle</param>
  50. /// <param name="keyMode">加密锁型号</param>
  51. /// <param name="keyVersion">硬件版本</param>
  52. /// <param name="e2size">存储区大小</param>
  53. /// <param name="ramSize">内存区大小</param>
  54. /// <param name="prouctionTime">生产日期</param>
  55. /// <returns></returns>
  56. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  57. public static extern int NTGetDevCaps(int NTHandle, int[] keyMode, int[] keyVersion, int[] e2size, int[] ramSize, byte[] prouctionTime);
  58. //获取硬件序列号
  59. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  60. public static extern int NTGetHarddwareID(int NTHandle, string hardwareID);
  61. //检测管理密码
  62. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  63. public static extern int NTCheckSuperPin(int NTHandle, string superin);
  64. //修改加密锁管理密码
  65. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  66. public static extern int NTSetSuperPin(int NTHandle, string newSPin);
  67. //修改加密锁登录密码
  68. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  69. public static extern int NTSetUserPin(int NTHandle, string superin, string seed, StringBuilder userPin);
  70. //修改加密锁识别码
  71. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  72. public static extern int NTSetAppName(int NTHandle, StringBuilder NTCode);
  73. //获得加密锁识别码
  74. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  75. public static extern int NTGetAppName(int NTHandle, StringBuilder NTCode);
  76. //读取存储区数据
  77. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  78. public static extern int NTRead(int NTHandle, int address, int length, byte[] pData);
  79. //读写存储区数据
  80. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  81. public static extern int NTWrite(int NTHandle, int address, int length, byte[] pData);
  82. //获取许可证标识及验证码
  83. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  84. public static extern int NTGetLicenseSettings(int NTHandle, byte[] licenseOption, int[] licenseCode, int licOptionNumber);
  85. //设置许可证标识,同时计算出验证码
  86. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  87. public static extern int NTGenLicenseCodes(int NTHandle, byte[] licenseOption, int[] licenseCode, int licOptionNumber);
  88. //验证许可证,输入相应额验证码进行验证
  89. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  90. public static extern int NTCheckLicense(int NTHandle, int licenseCode);
  91. //3DES加密
  92. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  93. public static extern int NT3DESCBCEncrypt(int NTHandle, byte[] iv, byte[] pDataBuffer, int length);
  94. //3DES设置
  95. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  96. public static extern int NTSet3DESKey(int NTHandle, byte[] key);
  97. //3DES解密
  98. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  99. public static extern int NT3DESCBCDecrypt(int NTHandle, byte[] iv, byte[] pDataBuffer, int length);
  100. //查询硬件ID
  101. [DllImport("NT88Mgr.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  102. public static extern int NTGetHardwareID(int NTHandle, StringBuilder hardwareID);
  103. #endregion
  104. /*****************************************/
  105. #region 应用层
  106. //查找加密锁
  107. [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  108. public static extern int NTFindFirst(string NTCode);
  109. //查询硬件ID
  110. [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  111. public static extern int NTGetHardwareID(StringBuilder hardwareID);
  112. //登录加密锁
  113. [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  114. public static extern int NTLogin(string NTpassword);
  115. //存储区数据读取
  116. [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  117. public static extern int NTRead(int address, int Length, byte[] pData);
  118. //存储区数据写入
  119. [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  120. public static extern int NTWrite(int address, int Length, byte[] pData);
  121. //3DES解密
  122. [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  123. public static extern int NT3DESCBCDecrypt(byte[] vi, byte[] pDataBuffer, int Length);
  124. //3DES加密
  125. [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  126. public static extern int NT3DESCBCEncrypt(byte[] vi, byte[] pDataBuffer, int Length);
  127. //验证许可证
  128. [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
  129. public static extern int NTCheckLicense(int licenseCode);
  130. //登出加密锁
  131. [DllImport("NT88.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
  132. public static extern int NTLogout();
  133. #endregion
  134. }