SoftKey.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. // JScript source code
  2. var HID = require('node-hid')
  3. const sm3 = require('sm3')
  4. var GETVERSION = 0x01
  5. var GETID = 0x02
  6. var GETVEREX = 0x05
  7. var CAL_TEA = 0x08
  8. var SET_TEAKEY = 0x09
  9. var READBYTE = 0x10
  10. var WRITEBYTE = 0x11
  11. var YTREADBUF = 0x12
  12. var YTWRITEBUF = 0x13
  13. var MYRESET = 0x20
  14. var YTREBOOT = 0x24
  15. var SET_ECC_PARA = 0x30
  16. var GET_ECC_PARA = 0x31
  17. var SET_ECC_KEY = 0x32
  18. var GET_ECC_KEY = 0x33
  19. var MYENC = 0x34
  20. var MYDEC = 0X35
  21. var SET_PIN = 0X36
  22. var GEN_KEYPAIR = 0x37
  23. var YTVERIFY = 0x52
  24. var GET_CHIPID = 0x53
  25. // errcode
  26. var FAILEDGENKEYPAIR = -21
  27. var FAILENC = -22
  28. var FAILDEC = -23
  29. var FAILPINPWD = -24
  30. var USBStatusFail = -50
  31. var ERR_SET_REPORT = -94
  32. var ERR_GET_REPORT = -93
  33. var MAX_LEN = 2031
  34. var SM2_ADDBYTE = 97//
  35. var MAX_ENCLEN = 128 //
  36. var MAX_DECLEN = (MAX_ENCLEN + SM2_ADDBYTE) //
  37. var SM2_USENAME_LEN = 80//
  38. var ECC_MAXLEN = 32
  39. var PIN_LEN = 16
  40. var MAX_TRANSE_LEN = 21
  41. var SM2_MAX_TRANSE_LEN = 255
  42. var ID_LEN = 16
  43. var mSoftKey = class SoftKey {
  44. SoftKey () {
  45. // connection object
  46. SoftKey.connection = null
  47. }
  48. GetLastError () {
  49. return this.lasterror
  50. }
  51. StrEnc (InString, Key) {
  52. var n; var m
  53. var nlen
  54. var b = Buffer.from(InString)
  55. var zero_buf = Buffer.from([0])
  56. b = Buffer.concat([b, zero_buf])
  57. nlen = b.length
  58. if (b.length < 8) {
  59. nlen = 8
  60. }
  61. var outb = Buffer.alloc(nlen)
  62. var inb = Buffer.alloc(nlen)
  63. b.copy(inb)// ???????8?????0????????????????0
  64. b.copy(outb)
  65. for (n = 0; n <= (nlen - 8); n = n + 8) {
  66. var tmpoutb = this.sub_EnCode(inb, n, Key)
  67. for (m = 0; m < 8; m++) {
  68. outb[m + n] = tmpoutb[m]
  69. }
  70. }
  71. return outb.toString('hex')
  72. }
  73. StrDec (InString, Key)//
  74. {
  75. var n, m
  76. var inb = new Buffer(InString, 'hex')
  77. var outb = Buffer.alloc(inb.length)
  78. inb.copy(outb)
  79. for (n = 0; n <= inb.length - 8; n = n + 8) {
  80. var tmpoutb = this.sub_DeCode(inb, n, Key)
  81. for (m = 0; m < 8; m++) {
  82. outb[m + n] = tmpoutb[m]
  83. }
  84. }
  85. return outb.toString()
  86. }
  87. EnCode (inb, Key) {
  88. this.sub_EnCode(inb, 0, Key)
  89. }
  90. sub_EnCode (inb, pos, Key) {
  91. var cnDelta, y, z, a, b, c, d
  92. var outb = new Uint8Array(8)
  93. var n, i, nlen
  94. var sum
  95. var temp, temp_1
  96. var buf = new Array(16)
  97. var temp_string
  98. cnDelta = 2654435769
  99. sum = 0
  100. nlen = Key.length
  101. i = 0
  102. for (n = 1; n <= nlen; n = n + 2) {
  103. temp_string = Key.substring(n - 1, n - 1 + 2)
  104. buf[i] = this.HexToInt(temp_string)
  105. i = i + 1
  106. }
  107. a = 0; b = 0; c = 0; d = 0
  108. for (n = 0; n <= 3; n++) {
  109. a = (buf[n] << (n * 8)) | a
  110. b = (buf[n + 4] << (n * 8)) | b
  111. c = (buf[n + 4 + 4] << (n * 8)) | c
  112. d = (buf[n + 4 + 4 + 4] << (n * 8)) | d
  113. }
  114. y = 0
  115. z = 0
  116. for (n = 0; n <= 3; n++) {
  117. y = (inb[n + pos] << (n * 8)) | y
  118. z = (inb[n + 4 + pos] << (n * 8)) | z
  119. }
  120. n = 32
  121. while (n > 0) {
  122. sum = cnDelta + sum
  123. temp = (z << 4) & 0xFFFFFFFF
  124. temp = (temp + a) & 0xFFFFFFFF
  125. temp_1 = (z + sum) & 0xFFFFFFFF
  126. temp = (temp ^ temp_1) & 0xFFFFFFFF
  127. temp_1 = (z >>> 5) & 0xFFFFFFFF
  128. temp_1 = (temp_1 + b) & 0xFFFFFFFF
  129. temp = (temp ^ temp_1) & 0xFFFFFFFF
  130. temp = (temp + y) & 0xFFFFFFFF
  131. y = temp & 0xFFFFFFFF
  132. // y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
  133. temp = (y << 4) & 0xFFFFFFFF
  134. temp = (temp + c) & 0xFFFFFFFF
  135. temp_1 = (y + sum) & 0xFFFFFFFF
  136. temp = (temp ^ temp_1) & 0xFFFFFFFF
  137. temp_1 = (y >>> 5) & 0xFFFFFFFF
  138. temp_1 = (temp_1 + d) & 0xFFFFFFFF
  139. temp = (temp ^ temp_1) & 0xFFFFFFFF
  140. temp = (z + temp) & 0xFFFFFFFF
  141. z = temp & 0xFFFFFFFF
  142. // z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
  143. n = n - 1
  144. }
  145. for (n = 0; n <= 3; n++) {
  146. outb[n] = ((y >>> (n * 8)) & 255)
  147. outb[n + 4] = ((z >>> (n * 8)) & 255)
  148. }
  149. return outb
  150. }
  151. DeCode () {
  152. sub_DeCode(inb, 0, Key)
  153. }
  154. sub_DeCode (inb, pos, Key) {
  155. var cnDelta, y, z, a, b, c, d
  156. var outb = new Uint8Array(8)
  157. var n, i, nlen
  158. var sum
  159. var temp, temp_1
  160. var buf = new Array(16)
  161. var temp_string
  162. cnDelta = 2654435769
  163. sum = 3337565984
  164. nlen = Key.length
  165. i = 0
  166. for (n = 1; n <= nlen; n = n + 2) {
  167. temp_ = Key.substring(n - 1, n - 1 + 2)
  168. buf[i] = this.HexToInt(temp_string)
  169. i = i + 1
  170. }
  171. a = 0; b = 0; c = 0; d = 0
  172. for (n = 0; n <= 3; n++) {
  173. a = (buf[n] << (n * 8)) | a
  174. b = (buf[n + 4] << (n * 8)) | b
  175. c = (buf[n + 4 + 4] << (n * 8)) | c
  176. d = (buf[n + 4 + 4 + 4] << (n * 8)) | d
  177. }
  178. y = 0
  179. z = 0
  180. for (n = 0; n <= 3; n++) {
  181. y = (inb[n + pos] << (n * 8)) | y
  182. z = (inb[n + 4 + pos] << (n * 8)) | z
  183. }
  184. n = 32
  185. while (n > 0) {
  186. temp = (y << 4) & 0xFFFFFFFF
  187. temp = (temp + c) & 0xFFFFFFFF
  188. temp_1 = (y + sum) & 0xFFFFFFFF
  189. temp = (temp ^ temp_1) & 0xFFFFFFFF
  190. temp_1 = (y >>> 5) & 0xFFFFFFFF
  191. temp_1 = (temp_1 + d) & 0xFFFFFFFF
  192. temp = (temp ^ temp_1) & 0xFFFFFFFF
  193. temp = (z - temp) & 0xFFFFFFFF
  194. z = temp & 0xFFFFFFFF
  195. // z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
  196. temp = (z << 4) & 0xFFFFFFFF
  197. temp = (temp + a) & 0xFFFFFFFF
  198. temp_1 = (z + sum) & 0xFFFFFFFF
  199. temp = (temp ^ temp_1) & 0xFFFFFFFF
  200. temp_1 = (z >>> 5) & 0xFFFFFFFF
  201. temp_1 = (temp_1 + b) & 0xFFFFFFFF
  202. temp = (temp ^ temp_1) & 0xFFFFFFFF
  203. temp = (y - temp) & 0xFFFFFFFF
  204. y = temp & 0xFFFFFFFF
  205. // y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
  206. sum = sum - cnDelta
  207. n = n - 1
  208. }
  209. for (n = 0; n <= 3; n++) {
  210. outb[n] = ((y >>> (n * 8)) & 255)
  211. outb[n + 4] = ((z >>> (n * 8)) & 255)
  212. }
  213. return outb
  214. }
  215. MacthUKeyID (mDevices) {
  216. if ((mDevices.vendorId == mSoftKey.VID && mDevices.productId == mSoftKey.PID) ||
  217. (mDevices.vendorId == mSoftKey.VID_NEW && mDevices.productId == mSoftKey.PID_NEW) ||
  218. (mDevices.vendorId == mSoftKey.VID_NEW_2 && mDevices.productId == mSoftKey.PID_NEW_2)) {
  219. return true
  220. }
  221. return false
  222. }
  223. /// //////////////////
  224. AddZero (InKey) {
  225. var nlen
  226. var n
  227. nlen = InKey.length
  228. for (n = nlen; n <= 7; n++) {
  229. InKey = '0' + InKey
  230. }
  231. return InKey
  232. }
  233. myconvert (HKey, LKey) {
  234. HKey = this.AddZero(HKey)
  235. LKey = this.AddZero(LKey)
  236. var out_data = new Uint8Array(8)
  237. var n
  238. for (n = 0; n <= 3; n++) {
  239. out_data[n] = this.HexToInt(HKey.substring(n * 2, n * 2 + 2))
  240. }
  241. for (n = 0; n <= 3; n++) {
  242. out_data[n + 4] = this.HexToInt(LKey.substring(n * 2, n * 2 + 2))
  243. }
  244. return out_data
  245. }
  246. /// /bin2hex & hex2bin
  247. ByteArrayToHexString (Inb, len) {
  248. var outstring = ''
  249. for (var n = 0; n <= len - 1; n++) {
  250. outstring = outstring + this.myhex(Inb[n])
  251. }
  252. return outstring
  253. }
  254. HexStringToByteArray (InString) {
  255. var nlen
  256. var retutn_len
  257. var n, i
  258. var b
  259. var temp
  260. nlen = InString.length
  261. if (nlen < 16) retutn_len = 16
  262. retutn_len = nlen / 2
  263. b = new Uint8Array(retutn_len)
  264. i = 0
  265. for (n = 0; n < nlen; n = n + 2) {
  266. temp = InString.substring(n, n + 2)
  267. b[i] = this.HexToInt(temp)
  268. i = i + 1
  269. }
  270. return b
  271. }
  272. /// /////
  273. // decimal to hex && hex2dec
  274. myhex (value) {
  275. if (value < 16) { return '0' + value.toString(16) }
  276. return value.toString(16)
  277. };
  278. HexToInt (s) {
  279. var hexch = '0123456789ABCDEF'
  280. var i, j
  281. var r, n, k
  282. var ch
  283. s = s.toUpperCase()
  284. k = 1; r = 0
  285. for (i = s.length; i > 0; i--) {
  286. ch = s.substring(i - 1, i - 1 + 1)
  287. n = 0
  288. for (j = 0; j < 16; j++) {
  289. if (ch == hexch.substring(j, j + 1)) {
  290. n = j
  291. }
  292. }
  293. r += (n * k)
  294. k *= 16
  295. }
  296. return r
  297. };
  298. /// /////////////
  299. /// //////////// send cmd only ,no carry data
  300. SendNoWithData (CmdFlag) {
  301. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  302. this.SendWithData(CmdFlag, array_in)
  303. return this.lasterror
  304. };
  305. /// ////////////////////////
  306. /* SendWithDataNoErr(CmdFlag,array_in,KeyPath) {
  307. this.lasterror=0;
  308. var featureReport = [2, 0];
  309. featureReport[1] = CmdFlag;
  310. for (var i = 1; i < array_in.length; i++) {
  311. featureReport[i + 1] =array_in[i];
  312. }
  313. if(KeyPath==null)
  314. {
  315. this.lasterror= -92;
  316. return array_out;
  317. }
  318. this.connection = new HID.HID(KeyPath)
  319. if(this.connection==null)
  320. {
  321. this.lasterror= -92;
  322. return array_out;
  323. }
  324. var Outlen=this.connection.sendFeatureReport( featureReport);
  325. if(Outlen<2) {this.connection.close();this.lasterror= ERR_SET_REPORT;return undefined;}
  326. var array_out=this.connection.getFeatureReport(1,SM2_MAX_TRANSE_LEN) ;
  327. this.connection.close();
  328. if(array_out.length<1){this.lasterror=ERR_GET_REPORT; return undefined;}
  329. return array_out;
  330. } */
  331. /// ////////send cmd and data
  332. SendWithDataNoErr (CmdFlag, array_in, KeyPath) {
  333. this.lasterror = 0
  334. var featureReport = [2]
  335. for (var n = 1; n <= SM2_MAX_TRANSE_LEN + 1; n++) {
  336. featureReport[n] = 0
  337. }
  338. featureReport[1] = CmdFlag
  339. for (var i = 1; i < array_in.length; i++) {
  340. featureReport[i + 1] = array_in[i]
  341. }
  342. if (KeyPath == null) {
  343. this.lasterror = -92
  344. return array_out
  345. }
  346. this.connection = new HID.HID(KeyPath)
  347. if (this.connection == null) {
  348. this.lasterror = -92
  349. return array_out
  350. }
  351. var Outlen = this.connection.sendFeatureReport(featureReport)
  352. if (Outlen < 2) { this.connection.close(); this.lasterror = ERR_SET_REPORT; return undefined }
  353. var array_out = this.connection.getFeatureReport(1, 510)
  354. this.connection.close()
  355. if (array_out.length < 1) { this.lasterror = ERR_GET_REPORT; return undefined }
  356. return array_out
  357. }
  358. SendWithData (CmdFlag, array_in, KeyPath) {
  359. var array_out = this.SendWithDataNoErr(CmdFlag, array_in, KeyPath)
  360. if (array_out[0] != 0) {
  361. this.lasterror = array_out[0] - 256
  362. } else {
  363. this.lasterror = 0
  364. }
  365. return array_out
  366. }
  367. /// ////////////
  368. GetOneByteDataFromUsbKey (cmd, KeyPath) {
  369. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  370. var array_out
  371. array_out = this.SendWithDataNoErr(cmd, array_in, KeyPath)
  372. if (this.lasterror) return undefined
  373. return array_out[0]
  374. }
  375. /// /////
  376. FindPort (start) {
  377. this.lasterror = 0
  378. var KeyPath = ''
  379. var count = 0
  380. var devices = HID.devices()
  381. devices.forEach(mDevice => {
  382. if (this.MacthUKeyID(mDevice)) {
  383. if (count == start) {
  384. KeyPath = mDevice.path
  385. return KeyPath
  386. }
  387. count++
  388. }
  389. })
  390. if (KeyPath != '') {
  391. this.lasterror = 0
  392. } else {
  393. this.lasterror = -92
  394. }
  395. return KeyPath
  396. }
  397. /// /////////////////////////////////////////////////////////////////////////////////
  398. NT_GetIDVersionEx (KeyPath) {
  399. return this.GetOneByteDataFromUsbKey(5, KeyPath)
  400. };
  401. NT_GetIDVersion (KeyPath) {
  402. return this.GetOneByteDataFromUsbKey(1, KeyPath)
  403. };
  404. /// //
  405. GetID (KeyPath) {
  406. var IDInfo = {
  407. ID_1: '',
  408. ID_2: ''
  409. }
  410. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  411. var array_out
  412. var t1 = new Buffer.alloc(4)
  413. var t2 = new Buffer.alloc(4)
  414. array_out = this.SendWithDataNoErr(2, array_in, KeyPath)
  415. if (this.lasterror != 0) { return '' }
  416. t1[0] = array_out[0]; t1[1] = array_out[1]; t1[2] = array_out[2]; t1[3] = array_out[3]
  417. t2[0] = array_out[4]; t2[1] = array_out[5]; t2[2] = array_out[6]; t2[3] = array_out[7]
  418. IDInfo.ID_1 = t1.toString('hex')
  419. IDInfo.ID_2 = t2.toString('hex')
  420. return IDInfo
  421. }
  422. GetChipID (KeyPath) {
  423. var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
  424. var array_out
  425. var OutChipID = ''; var outb = new Uint8Array(ID_LEN)
  426. array_out = this.SendWithDataNoErr(GET_CHIPID, array_in, KeyPath)
  427. if (this.lasterror != 0) { return '' }
  428. if (array_out[0] != 0x20) {
  429. this.lasterror = USBStatusFail
  430. return OutChipID
  431. }
  432. outb = array_out.slice(1, ID_LEN + 1)
  433. OutChipID = this.ByteArrayToHexString(outb, 16)
  434. OutChipID = OutChipID.toUpperCase()
  435. return OutChipID
  436. };
  437. /// /////
  438. /// //
  439. FindPort_2 (start, in_data, verf_data) {
  440. var n
  441. var count = 0
  442. var out_data = 0
  443. for (n = 0; n < 256; n++) {
  444. var KeyPath = this.FindPort(n)
  445. if (this.lasterror != 0) return null
  446. out_data = this.sWriteEx(in_data, KeyPath)
  447. if (this.lasterror != 0) return null
  448. if (out_data == verf_data) {
  449. if (start == count) return KeyPath
  450. count++
  451. }
  452. }
  453. return null
  454. };
  455. SetWritePassword (W_HKey, W_LKey, new_HKey, new_LKey, KeyPath) {
  456. var address
  457. var ary1 = this.myconvert(W_HKey, W_LKey)
  458. var ary2 = this.myconvert(new_HKey, new_LKey)
  459. address = 504
  460. this.lasterror = this.Sub_WriteByte(ary2, address, 8, ary1, 0, KeyPath)
  461. return this.lasterror
  462. }
  463. SetReadPassword (W_HKey, W_LKey, new_HKey, new_LKey, KeyPath) {
  464. var address
  465. var ary1 = this.myconvert(W_HKey, W_LKey)
  466. var ary2 = this.myconvert(new_HKey, new_LKey)
  467. address = 496
  468. this.lasterror = this.Sub_WriteByte(ary2, address, 8, ary1, 0, KeyPath)
  469. return this.lasterror
  470. }
  471. NT_SetCal (cmd, indata, IsHi, pos, KeyPath) {
  472. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  473. var n
  474. array_in[1] = IsHi
  475. for (n = 0; n < 8; n++) {
  476. array_in[2 + n] = indata[n + pos]
  477. }
  478. var array_out = this.SendWithData(cmd, array_in, KeyPath)
  479. if (this.lasterror != 0) return this.lasterror
  480. if (array_out[0] != 0) {
  481. this.lasterror = -82
  482. }
  483. return this.lasterror
  484. }
  485. Sub_SetCal (cmd, Key, KeyPath) {
  486. var KeyBuf = this.HexStringToByteArray(Key)
  487. this.lasterror = this.NT_SetCal(cmd, KeyBuf, 0, 8, KeyPath)
  488. if (this.lasterror != 0) return this.lasterror
  489. return this.NT_SetCal(cmd, KeyBuf, 1, 0, KeyPath)
  490. }
  491. SetCal_2 (Key, KeyPath) {
  492. return this.Sub_SetCal(SET_TEAKEY, Key, KeyPath)
  493. }
  494. SetCal_New (Key, KeyPath) {
  495. return this.Sub_SetCal(13, Key, KeyPath)
  496. }
  497. Sub_EncString (cmd, InString, KeyPath) {
  498. var n; var m
  499. var nlen
  500. var b = Buffer.from(InString)
  501. var zero_buf = Buffer.from([0])
  502. b = Buffer.concat([b, zero_buf])
  503. nlen = b.length
  504. if (b.length < 8) {
  505. nlen = 8
  506. }
  507. var outb = Buffer.alloc(nlen)
  508. var inb = Buffer.alloc(nlen)
  509. b.copy(inb)// ???????8?????0????????????????0
  510. b.copy(outb)
  511. for (n = 0; n <= (nlen - 8); n = n + 8) {
  512. var tmpoutb = this.NT_Cal(cmd, inb, n, KeyPath)
  513. for (m = 0; m < 8; m++) {
  514. outb[m + n] = tmpoutb[m]
  515. }
  516. if (this.lasterror != 0) ''
  517. }
  518. return outb.toString('hex')
  519. }
  520. EncString (InString, KeyPath) {
  521. return this.Sub_EncString(8, InString, KeyPath)
  522. }
  523. EncString_New (InString, KeyPath) {
  524. return this.Sub_EncString(12, InString, KeyPath)
  525. }
  526. NT_Cal (cmd, InBuf, pos, KeyPath) {
  527. var n
  528. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  529. var outbuf = new Uint8Array(8)
  530. for (n = 1; n <= 8; n++) {
  531. array_in[n] = InBuf[n - 1 + pos]
  532. }
  533. var array_out = this.SendWithDataNoErr(cmd, array_in, KeyPath)
  534. if (this.lasterror != 0) return undefined
  535. for (n = 0; n < 8; n++) {
  536. outbuf[n + pos] = array_out[n]
  537. }
  538. if (array_out[8] != 0x55) {
  539. this.lasterror = -20
  540. }
  541. return outbuf
  542. }
  543. Cal (Inbuf, KeyPath) {
  544. return this.NT_Cal(8, Inbuf, 0, KeyPath)
  545. }
  546. Cal_New (Inbuf, KeyPath) {
  547. return this.NT_Cal(12, Inbuf, 0, KeyPath)
  548. }
  549. SimpleCalData (cmd, in_data, KeyPath) {
  550. var t1
  551. var t2
  552. var t3
  553. var t4
  554. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  555. array_in[1] = (in_data & 255)
  556. array_in[2] = ((in_data >> 8) & 255)
  557. array_in[3] = ((in_data >> 16) & 255)
  558. array_in[4] = ((in_data >> 24) & 255)
  559. var array_out
  560. array_out = this.SendWithDataNoErr(cmd, array_in, KeyPath)
  561. if (this.lasterror != 0) { return 0 }
  562. t1 = array_out[0]
  563. t2 = array_out[1]
  564. t3 = array_out[2]
  565. t4 = array_out[3]
  566. return t1 | (t2 << 8) | (t3 << 16) | (t4 << 24)
  567. }
  568. sWriteEx (in_data, KeyPath) {
  569. return this.SimpleCalData(0x03, in_data, KeyPath)
  570. }
  571. sWrite_2Ex (in_data, KeyPath) {
  572. return this.SimpleCalData(0x04, in_data, KeyPath)
  573. }
  574. /// //////////////////
  575. Sub_WriteByte (indata, address, nlen, password, pos, KeyPath) {
  576. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  577. var addr_l
  578. var addr_h
  579. var n
  580. if ((address + nlen - 1) > (MAX_LEN + 17) || (address < 0)) return -81
  581. addr_h = (address >> 8) * 2
  582. addr_l = address & 255
  583. array_in[1] = addr_h
  584. array_in[2] = addr_l
  585. array_in[3] = nlen
  586. for (n = 0; n <= 7; n++) {
  587. array_in[4 + n] = password[n]
  588. }
  589. for (n = 0; n < nlen; n++) {
  590. array_in[12 + n] = indata[n + pos]
  591. }
  592. var array_out = this.SendWithDataNoErr(0x13, array_in, KeyPath)
  593. if (this.lasterror != 0) return this.lasterror
  594. if (array_out[0] != 0) {
  595. this.lasterror = -82
  596. }
  597. return this.lasterror
  598. }
  599. /// ///////////
  600. Sub_ReadByte (address, nlen, password, KeyPath) {
  601. var outData = new Uint8Array(nlen)
  602. var array_out
  603. var ret
  604. if (nlen > MAX_TRANSE_LEN) {
  605. this.lasterror = ERR_OVER_SEC_MAX_LEN
  606. return outData
  607. }
  608. if ((address + nlen > MAX_LEN)) {
  609. this.lasterror == ERR_OVER_SEC_MAX_LEN
  610. return outData
  611. }
  612. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  613. var addr_l
  614. var addr_h
  615. var n
  616. addr_h = (address >> 8) * 2
  617. addr_l = address & 255
  618. array_in[1] = addr_h
  619. array_in[2] = addr_l
  620. array_in[3] = nlen
  621. for (n = 0; n <= 7; n++) {
  622. array_in[4 + n] = password[n]
  623. }
  624. array_out = this.SendWithDataNoErr(0x12, array_in, KeyPath)
  625. if (this.lasterror != 0) return undefined
  626. if (array_out[0] != 0) {
  627. this.lasterror = -82; return outData
  628. }
  629. for (n = 0; n < (nlen); n++) {
  630. outData[n] = array_out[n + 1]
  631. }
  632. return outData
  633. }
  634. /// //////////////////////////
  635. YWriteEx (indata, address, nlen, HKey, LKey, KeyPath) {
  636. var ret = 0
  637. var n, trashLen = 16
  638. if ((address + nlen - 1 > MAX_LEN) || (address < 0)) return -81
  639. trashLen = trashLen - 8
  640. var password = this.myconvert(HKey, LKey)
  641. var tmplen
  642. var pos = 0
  643. while (nlen > 0) {
  644. if (nlen > trashLen) { tmplen = trashLen } else { tmplen = nlen }
  645. this.lasterror = this.Sub_WriteByte(indata, address + pos, tmplen, password, pos, KeyPath)
  646. if (this.lasterror != 0) { return this.lasterror }
  647. nlen = nlen - trashLen
  648. pos = pos + trashLen
  649. }
  650. return this.lasterror
  651. }
  652. /// ////////////////////////////
  653. YWriteString (InString, Address, HKey, LKey, KeyPath) {
  654. var Buf = Buffer.from(InString)
  655. this.YWriteEx(Buf, Address, Buf.length, HKey, LKey, KeyPath)
  656. if (this.lasterror < 0) return this.lasterror
  657. return Buf.length
  658. }
  659. /// ////////////
  660. YReadEx (address, nlen, HKey, LKey, KeyPath) {
  661. var ret = 0
  662. var password = new Uint8Array(8)
  663. var n, trashLen = 16
  664. var OutData = Buffer.alloc(0)
  665. var tmp_OutData
  666. if ((address + nlen - 1 > MAX_LEN) || (address < 0)) return (-81)
  667. password = this.myconvert(HKey, LKey)
  668. var tmplen
  669. var pos = 0
  670. while (nlen > 0) {
  671. if (nlen > trashLen) { tmplen = trashLen } else { tmplen = nlen }
  672. tmp_OutData = this.Sub_ReadByte(address + pos, tmplen, password, KeyPath)
  673. if (this.lasterror != 0) { return OutData }
  674. OutData = Buffer.concat([OutData, tmp_OutData])
  675. nlen = nlen - trashLen
  676. pos = pos + trashLen
  677. }
  678. return OutData
  679. }
  680. /// ///////////
  681. YReadString (Address, nlen, HKey, LKey, KeyPath) {
  682. var outData = this.YReadEx(Address, nlen, HKey, LKey, KeyPath)
  683. return outData.toString()
  684. }
  685. /// ////////////////////////////////////////////////// other api
  686. NT_ReSet (KeyPath) {
  687. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  688. var array_out = this.SendWithDataNoErr(MYRESET, array_in, KeyPath)
  689. if (this.lasterror != 0) return this.lasterror
  690. if (array_out[0] != 0) {
  691. this.lasterror = -82
  692. }
  693. return this.lasterror
  694. }
  695. ReSet (KeyPath) {
  696. this.lasterror = this.NT_ReSet(KeyPath)
  697. return this.lasterror
  698. }
  699. y_setcal (indata, password, KeyPath) {
  700. var n
  701. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  702. array_in[1] = 0
  703. array_in[2] = 0
  704. array_in[3] = 8
  705. for (n = 0; n <= 7; n++) {
  706. array_in[4 + n] = password[n]
  707. }
  708. for (n = 0; n < 8; n++) {
  709. array_in[12 + n] = indata[n]
  710. }
  711. var array_out = this.SendWithDataNoErr(6, array_in, KeyPath)
  712. if (this.lasterror) return this.lasterror
  713. if (array_out[0] != 0) {
  714. this.lasterror = -82
  715. }
  716. return this.lasterror
  717. }
  718. SetCal (HKey, LKey, new_HKey, new_LKey, KeyPath) {
  719. var ary1 = this.myconvert(HKey, LKey)
  720. var ary2 = this.myconvert(new_HKey, new_LKey)
  721. this.lasterror = this.y_setcal(ary2, ary1, KeyPath)
  722. return this.lasterror
  723. }
  724. NT_SetID (InBuf, KeyPath) {
  725. var n
  726. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  727. for (n = 1; n <= 8; n++) {
  728. array_in[n] = InBuf[n - 2]
  729. }
  730. var array_out = this.SendWithDataNoErr(7, array_in, KeyPath)
  731. if (this.lasterror != 0) return this.lasterror
  732. if (array_out[0] != 0) {
  733. this.lasterror = -82
  734. }
  735. return this.lasterror
  736. }
  737. SetID (Seed, KeyPath) {
  738. var KeyBuf = this.HexStringToByteArray(Seed)
  739. return this.NT_SetID(KeyBuf, KeyPath)
  740. }
  741. GetProduceDate (KeyPath) {
  742. var n
  743. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  744. var OutProduceDate = Buffer.alloc(8)
  745. var array_out = this.SendWithDataNoErr(15, array_in, KeyPath)
  746. if (this.lasterror != 0) return this.lasterror
  747. for (n = 0; n < 8; n++) {
  748. OutProduceDate[n] = array_out[n]
  749. }
  750. return OutProduceDate.toString('hex')
  751. }
  752. SetHidOnly (IsHidOnly, KeyPath) {
  753. return this.NT_SetHidOnly(IsHidOnly, KeyPath)
  754. }
  755. NT_SetHidOnly (IsHidOnly, KeyPath) {
  756. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  757. if (IsHidOnly) array_in[1] = 0; else array_in[1] = 0xff
  758. var array_out = this.SendWithDataNoErr(0x55, array_in, KeyPath)
  759. if (this.lasterror != 0) return this.lasterror
  760. if (array_out[0] != 0) {
  761. return -82
  762. }
  763. return 0
  764. }
  765. SetUReadOnly (KeyPath) {
  766. return this.NT_SetUReadOnly(KeyPath)
  767. }
  768. NT_SetUReadOnly (KeyPath) {
  769. var array_in = new Uint8Array(MAX_TRANSE_LEN)
  770. var array_out = this.SendWithDataNoErr(0x56, array_in, KeyPath)
  771. if (this.lasterror != 0) return this.lasterror
  772. if (array_out[0] != 0) {
  773. return -82
  774. }
  775. return 0
  776. }
  777. NT_Set_SM2_KeyPair (PriKey, PubKeyX, PubKeyY, sm2_UerName, KeyPath) {
  778. var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
  779. var n = 0
  780. for (n = 0; n < ECC_MAXLEN; n++) {
  781. array_in[1 + n + ECC_MAXLEN * 0] = PriKey[n]
  782. array_in[1 + n + ECC_MAXLEN * 1] = PubKeyX[n]
  783. array_in[1 + n + ECC_MAXLEN * 2] = PubKeyY[n]
  784. }
  785. for (n = 0; n < SM2_USENAME_LEN; n++) {
  786. array_in[1 + n + ECC_MAXLEN * 3] = sm2_UerName[n]
  787. }
  788. var array_out = this.SendWithDataNoErr(0x32, array_in, KeyPath)
  789. if (this.lasterror != 0) return this.lasterror
  790. if (array_out[0] != 0x20) this.lasterror = USBStatusFail
  791. return this.lasterror
  792. }
  793. NT_GenKeyPair (KeyPath) {
  794. var KEYPAIR = {
  795. PriKey: null,
  796. PubKeyX: null,
  797. PubKeyY: null
  798. }
  799. var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
  800. var n = 0
  801. var array_out = this.SendWithDataNoErr(GEN_KEYPAIR, array_in, KeyPath)
  802. if (this.lasterror != 0) return undefined
  803. if (array_out[0] != 0x20) {
  804. this.lasterror = FAILEDGENKEYPAIR; return undefined
  805. }
  806. KEYPAIR.PriKey = array_out.slice(1, 1 + ECC_MAXLEN)
  807. KEYPAIR.PubKeyX = array_out.slice(1 + ECC_MAXLEN, ECC_MAXLEN * 2 + 1)
  808. KEYPAIR.PubKeyY = array_out.slice(1 + ECC_MAXLEN * 2, ECC_MAXLEN * 3 + 1)
  809. return KEYPAIR
  810. }
  811. NT_Get_SM2_PubKey (KeyPath) {
  812. var SM2_PubKeyInfo = {
  813. KGx: null,
  814. KGy: null,
  815. sm2_UerName: null
  816. }
  817. var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
  818. var n = 0
  819. var array_out = this.SendWithDataNoErr(0x33, array_in, KeyPath)
  820. if (this.lasterror != 0) return this.lasterror
  821. if (array_out[0] != 0x20) {
  822. this.lasterror = USBStatusFail; return this.lasterror
  823. }
  824. SM2_PubKeyInfo.KGx = array_out.slice(1, 1 + ECC_MAXLEN * 1)
  825. SM2_PubKeyInfo.KGy = array_out.slice(1 + ECC_MAXLEN * 1, 1 + ECC_MAXLEN * 2)
  826. SM2_PubKeyInfo.sm2_UerName = array_out.slice(1 + ECC_MAXLEN * 2, 1 + ECC_MAXLEN * 2 + SM2_USENAME_LEN)
  827. return SM2_PubKeyInfo
  828. }
  829. NT_Set_Pin (old_pin, new_pin, KeyPath) {
  830. var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
  831. var n = 0
  832. var b_oldpin = Buffer.from(old_pin)
  833. var b_newpin = Buffer.from(new_pin)
  834. for (n = 0; n < PIN_LEN; n++) {
  835. array_in[1 + PIN_LEN * 0 + n] = b_oldpin[n]
  836. array_in[1 + PIN_LEN * 1 + n] = b_newpin[n]
  837. }
  838. var array_out = this.SendWithDataNoErr(SET_PIN, array_in, KeyPath)
  839. if (this.lasterror != 0) return this.lasterror
  840. if (array_out[0] != 0x20) {
  841. this.lasterror = USBStatusFail; return this.lasterror
  842. }
  843. if (array_out[1] != 0x20) {
  844. this.lasterror = FAILPINPWD
  845. }
  846. return this.lasterror
  847. }
  848. NT_SM2_Enc (inbuf, inlen, KeyPath) {
  849. var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
  850. var outbuf = new Uint8Array(inlen + SM2_ADDBYTE)
  851. var n = 0
  852. array_in[1] = inlen
  853. for (n = 0; n < inlen; n++) {
  854. array_in[2 + n] = inbuf[n]
  855. }
  856. var array_out = this.SendWithDataNoErr(MYENC, array_in, KeyPath)
  857. if (this.lasterror != 0) {
  858. return outbuf
  859. }
  860. if (array_out[0] != 0x20) {
  861. this.lasterror = USBStatusFail
  862. return outbuf
  863. }
  864. if (array_out[1] == 0) {
  865. this.lasterror = FAILENC
  866. return outbuf
  867. }
  868. for (n = 0; n < (inlen + SM2_ADDBYTE); n++) {
  869. outbuf[n] = array_out[2 + n]
  870. }
  871. return outbuf
  872. }
  873. NT_SM2_Dec (inbuf, inlen, pin, KeyPath) {
  874. var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
  875. var outbuf = new Uint8Array(inlen - SM2_ADDBYTE)
  876. var n = 0
  877. var b_pin = Buffer.from(pin)
  878. for (n = 0; n < PIN_LEN; n++) {
  879. array_in[1 + PIN_LEN * 0 + n] = b_pin[n]
  880. }
  881. array_in[1 + PIN_LEN] = inlen
  882. for (n = 0; n < inlen; n++) {
  883. array_in[1 + PIN_LEN + 1 + n] = inbuf[n]
  884. }
  885. var array_out = this.SendWithDataNoErr(MYDEC, array_in, KeyPath)
  886. if (this.lasterror != 0) {
  887. return outbuf
  888. }
  889. if (array_out[2] != 0x20) {
  890. this.lasterror = FAILPINPWD; return outbuf
  891. }
  892. if (array_out[1] == 0) {
  893. this.lasterror = FAILENC; return outbuf
  894. }
  895. if (array_out[0] != 0x20) {
  896. this.lasterror = USBStatusFail; return outbuf
  897. }
  898. for (n = 0; n < (inlen - SM2_ADDBYTE); n++) {
  899. outbuf[n] = array_out[3 + n]
  900. }
  901. return outbuf
  902. }
  903. sub_NT_Sign (cmd, inbuf, pin, KeyPath) {
  904. var outbuf = new Uint8Array(ECC_MAXLEN * 2)
  905. var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
  906. var n = 0
  907. var b_pin = Buffer.from(pin)
  908. for (n = 0; n < PIN_LEN; n++) {
  909. array_in[1 + PIN_LEN * 0 + n] = b_pin[n]
  910. }
  911. for (n = 0; n < 32; n++) {
  912. array_in[1 + PIN_LEN + n] = inbuf[n]
  913. }
  914. var array_out = this.SendWithDataNoErr(cmd, array_in, KeyPath)
  915. if (this.lasterror != 0) {
  916. return outbuf
  917. }
  918. if (array_out[1] != 0x20) {
  919. this.lasterror = FAILPINPWD
  920. return outbuf
  921. }
  922. if (array_out[0] != 0x20) {
  923. this.lasterror = USBStatusFail
  924. return outbuf
  925. }
  926. for (n = 0; n < ECC_MAXLEN * 2; n++) {
  927. outbuf[n] = array_out[2 + n]
  928. }
  929. return outbuf
  930. }
  931. NT_Sign (inbuf, pin, KeyPath) {
  932. return this.sub_NT_Sign(0x51, inbuf, pin, KeyPath)
  933. }
  934. NT_Sign_2 (inbuf, pin, KeyPath) {
  935. return this.sub_NT_Sign(0x53, inbuf, pin, KeyPath)
  936. }
  937. NT_Verfiy (inbuf, InSignBuf, KeyPath) {
  938. var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
  939. var n = 0
  940. for (n = 0; n < ECC_MAXLEN; n++) {
  941. array_in[1 + n] = inbuf[n]
  942. }
  943. for (n = 0; n < ECC_MAXLEN * 2; n++) {
  944. array_in[1 + ECC_MAXLEN + n] = InSignBuf[n]
  945. }
  946. var array_out = this.SendWithDataNoErr(YTVERIFY, array_in, KeyPath)
  947. if (this.lasterror != 0) return false
  948. var outbiao = (array_out[1] != 0)
  949. if (array_out[0] != 0x20) {
  950. this.lasterror = USBStatusFail; return false
  951. }
  952. return outbiao
  953. }
  954. YT_GenKeyPair (KeyPath) {
  955. var n
  956. var KeyPairInfo = {
  957. PriKey: '',
  958. PubKeyX: '',
  959. PubKeyY: ''
  960. }
  961. var KEYPAIR = this.NT_GenKeyPair(KeyPath)
  962. if (this.lasterror) return KeyPairInfo
  963. KeyPairInfo.PriKey = this.ByteArrayToHexString(KEYPAIR.PriKey, ECC_MAXLEN)
  964. KeyPairInfo.PubKeyX = this.ByteArrayToHexString(KEYPAIR.PubKeyX, ECC_MAXLEN)
  965. KeyPairInfo.PubKeyY = this.ByteArrayToHexString(KEYPAIR.PubKeyY, ECC_MAXLEN)
  966. return KeyPairInfo
  967. }
  968. Set_SM2_KeyPair (PriKey, PubKeyX, PubKeyY, SM2_UserName, KeyPath) {
  969. var b_PriKey = this.HexStringToByteArray(PriKey)
  970. var b_PubKeyX = this.HexStringToByteArray(PubKeyX)
  971. var b_PubKeyY = this.HexStringToByteArray(PubKeyY)
  972. var b_SM2UserName = Buffer.from(SM2_UserName)
  973. return this.NT_Set_SM2_KeyPair(b_PriKey, b_PubKeyX, b_PubKeyY, b_SM2UserName, KeyPath)
  974. }
  975. Get_SM2_PubKey (KeyPath) {
  976. var PubKeyInfo = {
  977. PubKeyX: '',
  978. PubKeyY: '',
  979. sm2UserName: ''
  980. }
  981. var SM2_PubKeyInfo = this.NT_Get_SM2_PubKey(KeyPath)
  982. PubKeyInfo.PubKeyX = this.ByteArrayToHexString(SM2_PubKeyInfo.KGx, ECC_MAXLEN)
  983. PubKeyInfo.PubKeyY = this.ByteArrayToHexString(SM2_PubKeyInfo.KGy, ECC_MAXLEN)
  984. PubKeyInfo.sm2UserName = new Buffer(SM2_PubKeyInfo.sm2_UerName).toString()
  985. return PubKeyInfo
  986. }
  987. SM2_EncBuf (InBuf, inlen, KeyPath) {
  988. var n, temp_inlen, incount = 0, outcount = 0
  989. var temp_InBuf = new Uint8Array(MAX_ENCLEN + SM2_ADDBYTE)
  990. var OutBuf = Buffer.alloc(0)
  991. // InBuf.copy(OutBuf);
  992. while (inlen > 0) {
  993. if (inlen > MAX_ENCLEN) { temp_inlen = MAX_ENCLEN } else { temp_inlen = inlen }
  994. for (n = 0; n < temp_inlen; n++) {
  995. temp_InBuf[n] = InBuf[incount + n]
  996. }
  997. var temp_OutBuf = this.NT_SM2_Enc(temp_InBuf, temp_inlen, KeyPath)
  998. if (this.lasterror) return OutBuf
  999. OutBuf = Buffer.concat([OutBuf, temp_OutBuf])
  1000. inlen = inlen - MAX_ENCLEN
  1001. incount = incount + MAX_ENCLEN
  1002. outcount = outcount + MAX_DECLEN
  1003. }
  1004. return OutBuf
  1005. }
  1006. SM2_DecBuf (InBuf, inlen, pin, KeyPath) {
  1007. var temp_inlen, n, incount = 0, outcount = 0
  1008. var temp_InBuf = new Uint8Array(MAX_ENCLEN + SM2_ADDBYTE)
  1009. var OutBuf = Buffer.alloc(InBuf.length)
  1010. // var b=new Buffer(InBuf)
  1011. // b.copy(OutBuf);
  1012. var OutBuf = Buffer.alloc(0)
  1013. while (inlen > 0) {
  1014. if (inlen > MAX_DECLEN) { temp_inlen = MAX_DECLEN } else { temp_inlen = inlen }
  1015. for (n = 0; n < temp_inlen; n++) {
  1016. temp_InBuf[n] = InBuf[incount + n]
  1017. }
  1018. var temp_OutBuf = this.NT_SM2_Dec(InBuf, temp_inlen, pin, KeyPath)
  1019. if (this.lasterror) return OutBuf
  1020. OutBuf = Buffer.concat([OutBuf, temp_OutBuf])
  1021. inlen = inlen - MAX_DECLEN
  1022. incount = incount + MAX_DECLEN
  1023. outcount = outcount + MAX_ENCLEN
  1024. }
  1025. return OutBuf
  1026. }
  1027. SM2_EncString (InString, KeyPath) {
  1028. var InBuf = Buffer.from(InString)
  1029. var OutBuf = this.SM2_EncBuf(InBuf, InBuf.length, KeyPath)
  1030. if (this.lasterror) return OutBuf
  1031. return this.ByteArrayToHexString(OutBuf, OutBuf.length)
  1032. }
  1033. SM2_DecString (InString, pin, KeyPath) {
  1034. var InBuf = this.HexStringToByteArray(InString)
  1035. var OutBuf = this.SM2_DecBuf(InBuf, InBuf.length, pin, KeyPath)
  1036. return OutBuf.toString()
  1037. }
  1038. YtSetPin (old_pin, new_pin, KeyPath) {
  1039. return this.NT_Set_Pin(old_pin, new_pin, KeyPath)
  1040. }
  1041. Sub_YtSign (cmd, msg, pin, KeyPath) {
  1042. var OutSign
  1043. var MsgHashValue = sm3(msg)
  1044. var Inbuf = new Buffer.from(MsgHashValue, 'hex')
  1045. var OutBuf = this.sub_NT_Sign(cmd, Inbuf, pin, KeyPath)
  1046. if (this.lasterror != 0) return OutSign
  1047. OutSign = new Buffer(OutBuf).toString('hex')
  1048. return OutSign
  1049. }
  1050. YtSign (msg, pin, KeyPath) {
  1051. return this.Sub_YtSign(0x51, msg, pin, KeyPath)
  1052. }
  1053. YtSign_2 (msg, pin, KeyPath) {
  1054. return this.Sub_YtSign(0x53, msg, pin, KeyPath)
  1055. }
  1056. CheckKeyByFindort_2 () {
  1057. // ??????????????????????
  1058. var DevicePath = '' // ??????????????��??
  1059. DevicePath = this.FindPort_2(0, 1, -909931691)
  1060. return this.lasterror
  1061. }
  1062. // ??????????????????????��???????
  1063. ReadStringEx (addr, DevicePath) {
  1064. var nlen
  1065. // ?????0??????��????????????
  1066. var OutData = this.YReadEx(addr, 1, '6398277A', '8388014E', DevicePath)
  1067. if (this.lasterror != 0) return ''
  1068. nlen = OutData[0]
  1069. // ?????????????????
  1070. return this.YReadString(addr + 1, nlen, '6398277A', '8388014E', DevicePath)
  1071. }
  1072. // ??????????????????????????????????????????
  1073. CheckKeyByReadEprom () {
  1074. var n, ret
  1075. // @NoUseCode_data return 1;//???????????????????????1
  1076. for (n = 0; n < 255; n++) {
  1077. var DevicePath = this.FindPort(n)// ??????????????��??
  1078. if (this.lasterror != 0) return this.lasterror
  1079. var outString = this.ReadStringEx(0, DevicePath)
  1080. if ((this.lasterror == 0) && (outString == 'FM1XhyDQ5z0DIISIhvu6uwTP8uBUxtnK')) return 0
  1081. }
  1082. return -92
  1083. }
  1084. // ????????????????????????????????��????????
  1085. CheckKeyByEncstring () {
  1086. // ???????????????????????????????????????????????????????????????????????��??
  1087. var n, ret
  1088. var InString
  1089. // @NoUseKeyEx return 1;//???????????????????????1
  1090. var number1 = Math.floor(Math.random() * 65535)
  1091. var number2 = Math.floor(Math.random() * 65535)
  1092. InString = number1.toString() + number2.toString()
  1093. for (n = 0; n < 255; n++) {
  1094. var DevicePath = this.FindPort(n)// ??????????????��??
  1095. if (this.lasterror != 0) return this.lasterror
  1096. if (this.Sub_CheckKeyByEncString(InString, DevicePath) == 0) return 0
  1097. }
  1098. return -92
  1099. }
  1100. Sub_CheckKeyByEncString (InString, DevicePath) {
  1101. // ???????????????????��???
  1102. var outString = this.EncString(InString, DevicePath)
  1103. if (this.lasterror != 0) return this.lasterror
  1104. var outString_2 = this.StrEnc(InString, '4326BBDEB43352C31FED71B466A0E879')
  1105. if (outString_2.toUpperCase() == outString.toUpperCase())// ???????????
  1106. {
  1107. return 0
  1108. }
  1109. return -92
  1110. }
  1111. // ??????????????????????????????????��??????????
  1112. CheckKeyByEncstring_New () {
  1113. var n, ret
  1114. var myrnd = Math.floor(Math.random() * 500)
  1115. var EncInString = ['3464', '523', '19087', '14042', '30839', '6180', '9099', '31244', '25703', '21437', '4745', '26555', '2913', '11960', '12769', '6362', '27278', '22933', '30735', '4601', '15419', '19833', '428', '25929', '4559', '32292', '31602', '29855', '3542', '11258',
  1116. '11323', '21356', '15864', '22010', '7938', '18625', '5377', '19400', '27871', '29008', '1242', '24486', '9998', '366', '14476', '14453', '24807', '9992', '28227', '17336', '23014', '2996', '29000', '18321', '18340', '30370', '13317', '5314', '16347', '3749',
  1117. '2565', '22699', '16997', '15406', '497', '3921', '25404', '11089', '24465', '5461', '5243', '28093', '13780', '23031', '4187', '15559', '8384', '12572', '25397', '23390', '8064', '17732', '5509', '6168', '3678', '10641', '30179', '28450', '16580', '3015',
  1118. '780', '19538', '15164', '1606', '30166', '27929', '3441', '4624', '27455', '25224', '19499', '6345', '11871', '13138', '11094', '9904', '8815', '7625', '14331', '15530', '19659', '31197', '12868', '16951', '32491', '15139', '1915', '6010', '8300', '4812',
  1119. '27658', '18228', '6405', '12712', '5500', '22727', '23184', '10796', '5241', '16951', '2826', '29287', '20172', '31268', '20106', '1551', '6496', '10705', '12620', '10354', '29246', '32543', '12713', '18052', '23184', '7826', '27162', '30934', '20640', '13641',
  1120. '23355', '9628', '27096', '11017', '21957', '17062', '3267', '29745', '1171', '14182', '19209', '967', '5789', '24303', '23413', '23912', '2303', '10739', '13298', '18266', '4337', '24771', '17289', '7294', '9679', '1363', '19556', '15957', '11025', '21810',
  1121. '24013', '9986', '14931', '27540', '28206', '6982', '3406', '844', '5394', '31875', '2013', '22728', '25889', '15037', '25079', '11295', '26151', '26260', '29114', '25343', '12045', '25419', '5470', '19133', '8157', '14532', '15676', '31304', '15297', '1408',
  1122. '5584', '21557', '8963', '4258', '20915', '10421', '11533', '31722', '5023', '30616', '8809', '5566', '30830', '21075', '5826', '19228', '16666', '24054', '25312', '14761', '7358', '30004', '16047', '24996', '4755', '27230', '31543', '30705', '3058', '26983',
  1123. '23717', '22547', '32342', '31201', '5184', '5674', '13659', '8446', '23155', '12536', '15544', '9103', '10441', '25568', '27208', '26629', '5098', '6372', '2054', '30837', '17826', '31396', '7690', '9361', '5850', '9830', '23695', '17320', '18843', '32263',
  1124. '9712', '5806', '25361', '6670', '14502', '18997', '9605', '23449', '31050', '6254', '10850', '7789', '23704', '2860', '7216', '2794', '29033', '24032', '4251', '2067', '2744', '32669', '619', '19849', '2462', '13589', '27531', '5519', '18260', '23193',
  1125. '32518', '28422', '7990', '17949', '774', '12145', '6333', '18736', '19154', '1266', '12674', '21254', '20696', '10314', '18241', '12914', '28831', '11996', '8660', '30690', '16595', '31913', '7475', '30573', '3389', '22101', '29561', '27329', '28870', '4896',
  1126. '9953', '13107', '3962', '28396', '3012', '15283', '28801', '31804', '29339', '31443', '30759', '13874', '29186', '5319', '471', '12943', '20658', '7519', '6679', '29622', '3974', '31245', '22675', '23208', '4982', '25572', '23061', '14601', '28573', '2455',
  1127. '23176', '793', '20277', '20853', '28405', '8634', '32665', '15218', '24454', '25711', '6722', '25375', '8581', '4954', '20170', '8624', '29020', '8508', '19691', '20468', '3222', '32120', '20095', '10336', '3036', '1552', '16768', '18692', '23799', '6565',
  1128. '4617', '21907', '23762', '18810', '5203', '14686', '4473', '11120', '3767', '2393', '1043', '19466', '25521', '1555', '15083', '16490', '23514', '15808', '21355', '22609', '4076', '20018', '15389', '28706', '29377', '18139', '3756', '25310', '31571', '10956',
  1129. '2529', '7209', '28348', '4792', '11173', '19011', '18999', '28400', '27395', '12302', '19741', '26983', '4647', '5902', '8936', '26542', '14424', '24930', '11570', '11513', '23553', '15310', '28084', '7192', '7341', '28596', '4171', '6525', '5380', '21782',
  1130. '5358', '3388', '21713', '25749', '6585', '1285', '31487', '26995', '17636', '30249', '28567', '21396', '20171', '8094', '15811', '10616', '11239', '3058', '3534', '6722', '22225', '13145', '16159', '12211', '14917', '15781', '8772', '8239', '15133', '25671',
  1131. '21220', '16565', '25169', '29778', '12747', '5865', '9980', '28792', '32481', '2829', '22617', '21259', '4915', '14850', '10177', '28668', '15079', '26443', '21165', '30429' ]
  1132. var EncOutString = [ '9109AF1823AC1B2E', '8FF16FAD925B3F01', '0F891E813D230312', '257E088892733D04', 'FA9922B0A1360B55', 'B33DC34B81BF0017', '6EA56A939D566A16', 'B6B162FF1539EBB0', 'A5BA1E6EC1EBA566', '672E13C6688B11D3', 'F8AF5D4DF00176EC', '4307A9A17B8EB534', '0A6B1CE1505C9C3B', '36BCBB60DF4CFA34', 'E244F1EB013BB416', '42779C67BAAF1BB8', 'A6D11367F6C30D8B', 'FED1AAFFB2962B9C', '36106445DC6D995B', '9E6F5DAC8D2D0815', '63EF28166C337645', '8138CA0B6675D476', 'CFA083CF7498FD0D', '9EC8D85B8F67042E', '34E4058C84993C80', '001A5F5230FF7A5A', 'FDDEAFB2790EED2E', '3F61E125F5946565', 'DFA6772958457B8E', '557F68AF936EEB8D',
  1133. '0590AF328DBB842B', '11B7488F86A4A4EC', '9F70C5CA4216ADA2', '867920BB3489258A', 'B945A47F59BBBC21', '435E1AF8D13ADE16', '97593D5A962EF62A', '941499AC5C618F51', '305C73D522685F28', '50C3414075DD8DE3', 'ABC42C7BF1A72242', '68517095358C6BEC', '3C6D3EDEECC9ACB5', '4BD9A9EAEBA22305', '3A6D25CF7409F7D5', '30519449D9EE1174', 'D7A6B461F4814AC3', 'D0DEC28879A715FB', '14C1FE8C5D8367EA', '6FED8696332CC371', '22A6E4861BACDD11', 'F16C8F46F302073B', 'D4851145AA118AF6', '675EB5D4249B6998', 'DF28039FD617F567', '195DBF181C213583', '71E2EEA862F68E98', '17F603A8852C5E19', 'D71F94BE53748C69', '24E7ABD2DD834F71',
  1134. 'E7AEDC577C43F04C', 'FA2B7886075BA9C3', '12BAEA8F2E75C36A', '12D730FDB8A63F23', '0ADC5A1B05B36C1A', '81E2C39C49BA395E', '72A12EFF93FE7659', '55378A6AF863AA37', '976CB44922D4CF4D', 'A5F287AED3434A46', 'FF2217A567B5C5FA', '695DF1B2FBEF7207', 'B93DFD16D17CD63F', '4A77B25EFC8D1418', '7E6BB6B266340F5E', '0B01D2FF27B44FA2', 'D46900702E397CF2', 'AF2F8562DA76DCDE', '6FC76138432E9AAE', '860BCDD8F8E596D6', '1F108E52BB9E8738', '97D9FEF60E79309C', '789E6E77CB2579B8', 'DBF4BEF4EECA4723', '4A708F83B5123736', '41CBEBC704E7EBEC', '5CC832301C175AAC', '78E1DDFB8023B4BB', '7065341838BF606C', 'D9A8A20000B8DAA9',
  1135. 'A6DBD8B98698EEC9', '3CF88FDF56B45C1F', 'E30978D817904E68', 'DCAC124DFBD35CEC', '902FAA95DB1D3270', '230A65A7A496ACA4', '7385F440092E372B', '90CBACE316035F8E', '50994BC4299EC6DC', '8424F2E73F604057', 'D80B988E03F04780', '62CE1BF4DC365EF1', 'C9908B62E3F085CE', '88873BBEF73BF30E', '8CBBC7503A8BFD34', 'A3799B33291B5B3C', '33C12E0095A3E770', 'E5678E0752C8DA10', '6362445CAD3E6D1A', 'F5F318F5C2A14231', '1820A3639E460A1A', '4AAC5FF2533EFE2E', '1BB9B116834D5527', '08C26B9170FB25F1', '05E13D9D171391A9', 'E01788AA0E8AC92C', '2D9707C3F6867450', 'ABA34ED5057E611F', '8D3A5C823544FC25', 'C4BD6150F95C6512',
  1136. 'C63B7CEE613CA5EA', '1F82AD8E1BF14ED0', '5AAA170F91EA6595', 'EBC54EB3571DBB16', '21B9585E4C75BE63', '33A1245417514454', '0182B1F20FDB2D8C', '7F2F3CF43867D1F5', 'AF8D318040A2AD86', '08C26B9170FB25F1', '91427B9C522CA50E', '0229CBC450CC1C14', 'B2637DA1062357E5', '806D8DE027B9B401', '1D610CA06FE2C0C2', 'C913AF1C90ACC767', '23CF7623D399C55F', '428DC5DD541F507A', '9A3A3CD81A9B0CE5', '748848D61E21A1EB', '712B25D2AD1E170E', '3AA776043C539267', '71836383483B168A', '1345707DCFCF0AEB', '0182B1F20FDB2D8C', '2FF3851CCCE70D40', '37CEE8E6EDAA088E', 'F9BF0824EF9887D7', '015461758A8F9B19', '2089DCA339260CEB',
  1137. '16131BBA8F123952', 'B906CF8635082E48', '238295F5A5D3499C', '1B2ACEFE1FBBCF30', 'C358E6A0BEF7B9AC', 'D20F3C7E6A4B2675', 'C272F71ADCA93FC1', '33D02C5A3CD909C4', '22147AAA0732FD4C', '93148F917AA3F697', '9E1C2EA52DC38C61', '39A2ED0E45BE86E2', 'F4AA970F93A70193', 'CC06EF42AB185316', '10B7AB3F48E0AA1B', 'BC1CE46DBE02E955', '3A76C0563C36E14D', '25BABDA75CDE95B0', '246FE5E85FC1604A', '2D78FB9DE70DA314', 'F2CA9C3BF0B8B776', '8553F4097A1D2BED', 'F1AC0344EB0F6F9B', '77DF640C0549A36D', '9F06A95158595BF0', '5D410787B63B00D5', '926E7577FD4971B9', '2781534EE8C7B2F0', '37043E43B7F1AF10', '5F8D68B53BBE3472',
  1138. '44FE191ECD2AC685', '455C5BA1D0E02EBE', 'C4F22B60EA5E5661', '2F66D8DEC556674F', 'EEACADB2B2E99886', '41E222611A10A18D', '86F6F28BE8ED55D4', 'BFDB93998246EAE9', '52FF950729722F03', '6C4BE5362B6BB35B', 'A91A8F0CAF84B84F', '661374EE955A0C31', '8720006A408F1E45', 'D360E64C21DFB154', '2F14CE39829C87A9', '13F31E2E54FAAA83', '6E29AE456BB428E4', '09320C7F72E5BF59', 'B8421A351C21BC82', 'AA2F338A4DC6EB0A', 'DC4E96D7F1D55AE3', '75F7D4C5FA53605D', 'C4DBB8907A8FEEB7', '619AE245350826EC', 'BC804ABAED584712', '8E35C2E23EDA5BDB', '709021194FEDDF28', 'B265C50C1F8BE10E', '4C1E7C9AE97848F8', 'E28DC8C07390F122',
  1139. '7FB8992410306291', '745302008FEE1B4E', '4CCD11CDC3AEFE86', '2F61235EF81060F1', 'DC1BE3414B698270', '8057C8D2C0709945', '3AA6F9D326EA98AA', '68D7F76DE46DC061', 'E35A68AA39E19A9D', '132DAA287820ABE9', '6401924840708E05', 'D008DB76D6147877', '5DFF0592EC2BE440', '7618F774869E3859', 'E1732890E482FFCE', '8ED4B800220FC19D', '781E3959A0BB7C8C', '310095EA9D11840D', '5DD63DB90BDA3E1D', 'A631075E70DCCAAE', 'E587616F17D3588D', '66980CDA7A1F7586', '9131FDCAB4518A05', 'F67835137BA612B1', '7E11329982E76B64', 'DD5135143797EC59', '5DA154ECC59C397C', '367C28F8986C6445', '82158F47205BA3CB', 'CC7A432B9DDC131D',
  1140. 'EDB58268D9C6C1E8', 'B5CF7B85B7A1CFA4', '54AF5C48EC8FE006', '2B47818C7B252A8C', '0931D257398A1836', 'CE126263E38D4310', '347CC924E131C7CC', '1C2EAD3FAA1E0A2E', 'F7572A6C6A625169', '2CA98893790E5BC9', 'C5AC8D426914C6DB', 'F25C688CB9DA6239', '80FEF695B1985711', 'A02FEBCF76F3C930', 'DA28075647864781', 'D2182A6F7F569F21', '7D95E2FFE847EB3A', '15BD219DC43EE2D3', '09F70979C0283C75', '433F658ED7332461', 'F37B73D266809E10', 'E68AF5E9CDC97275', '4CF08D24A01D6E5C', 'A318B464B807074C', '444EA572CDE886AB', '00BEF4620A2049EA', '4AF48665C2AD05BE', 'F4A084DA44647B86', '3C447473854F4F07', '3E2ECDAC57863C40',
  1141. '366CB6DA2945E888', 'E6C81E67611B394C', '516FA7AC61430E65', 'F6CCBF83F092772D', 'FAE6D63DCEDC7424', '4B29E8C16AFFD465', 'B49EE159212A8CD4', '395AA8CAF344444D', 'FD20B9EA744B67C2', '665D69A50A2312FD', '6964D3398A466895', '3EFC7384869C1A15', '677B184F9126CC24', '41C20BC7A73D751D', '52570795B4CE4100', '07F300B70799185F', '6CF45C252C756C4F', '318B78FAE5AEC7B4', '8A80AD140399DFB1', 'A9EFBF416F03A688', 'D4EF919C0A63A0D9', '20170DC07738F8EE', '622305DD424115B2', 'EC6A80BB7DC7DC76', '20C161340675924F', '97DF542ADB1EE36A', 'F2651FFA2E98C945', '25099BC221CD55DC', 'DFBEB6ED6F47A4F6', 'BED58AA37233B61B',
  1142. '471A0C433AE6E3F5', '809EB6B2652403B8', '06FDD21E1A34AE95', 'FE900FE205DB6804', 'CB17AE9595BB0CAF', 'D79CED999BAB308D', '6C206895EC5FB2AE', 'C1EBEEC719DCA782', '27A89EEE892525DC', '7FC9EF897AF53946', '65924B77A261D8D5', '4287581DFB54553A', '080CB3BC0CC73FE0', '4EF883D8B8E890F7', '8AAB9E45BE6F2A8B', '2A967F887CF6B932', '183B7F2F806C7A08', '497766D7E43FBC90', 'ACF6CEF60D067F31', '60C945085AD30388', '6839CE42FEF1D8EC', 'E6DDAAC68E266B43', '5345A0878CAB40D6', '838E2D23F4A689F4', '52A3F0B4E326DE1C', '12B9EDAC4DB689E9', 'DE70F460116E12EB', '0DA823A7232CAEEF', '8FEB9A481FDA0F6C', 'D3B91004CC7547A0',
  1143. '42886EA50E47AE4A', '350FB8D722C9253E', '72771743F76AFF85', '0B86E907E32820F0', '9471F81DE765BD0E', '20C9683E86618129', '6BDE6248C521A55D', '0C0BE96C6C68CC70', '2719F87B104B5374', '74CC2CAF52F6603D', '8BCCD192DABFA0AC', '93D60806FEDEC822', '7D53A5BFACFDD15E', 'CC2D855B5AE06856', 'F1E8124583D6CE0D', '84AE3B11BEA8FAAF', 'A51FB879A36DE970', '3CCFC90915D701B7', '6E29EB5554007F0D', 'DF4FAF51894CC584', 'ED31043EA5573B80', 'CC342292E3E483BB', '1B14F0ECCF1CBFFD', 'CE13596F6A4663CB', '6D6331DAE4542041', '8670DF086AADBC0B', '4E91335D3E709D9F', '422C0A5604DD0902', '98BBE7F47CDD5B60', '30B911E6D60DAC7E',
  1144. 'D590AF64FFCE67AB', '55A4ABBA6654A329', 'B8D48F2A6EB51854', 'E993F6CA6392FE1D', '6443EF045C53DFD9', '9D7952BCA9E663F0', '5A1F24E4877BAFB7', '91425ACD75BD5471', '14BBA0F6D5289D6E', '936FD61582B9659F', '1703786B5945840C', 'E48F8102B13B5120', '80662E3785BB16D8', '76FE236AE34CDE51', 'FA1E6E2B2BB5FA30', '56C3431E8B460660', '99F5112AD55DD450', '1374AD80CD3BE628', 'AE11E4275FC6B16E', 'BEAAEB8471DB6B5A', '4D7B7F69F0918D14', '87E2AED61D6BDD95', '231D016B6C446987', 'D03ADDCF8449F653', 'BE861C24231A29AA', '894942FBD77332AD', '1A0C03E662EE8CEE', '53872FE34867AC3A', '1BCC1737F5030D08', 'F6A1D639EF409699',
  1145. 'AF6F6866911F77B5', '3420F592EBA5CEE0', '4D186DF8111520F6', '1D24B43879130953', 'CE6495E67CE887F4', 'F198EFEB33654EF0', '8A08112132477BE5', '87537FB5B16B6970', '7C0470752CEF0104', 'C2B6417168D77CC7', '64628F5DD2066BCF', 'E9756AAD11124B51', 'C385EFC79BB2D2DB', '83CCE9AE3B4AACFA', '45D954E5C89FB04B', 'C4EA3C2FFDB75969', '3CE04C80B2603484', '14C8E18205C77E83', 'E6BF69428438246C', 'F9A51079E3839423', 'FF601291926770B2', '382915FD6974687D', '0B436D1FF525897C', '33FEC0C69A6B521C', '3F0383147954B970', '82158DC00B34B64B', '1B2913C253E9A7A0', '087E2ED4E6C68EB3', '069F387B79486C16', '908B1EC06F4DAFD8',
  1146. 'E66FD6C356D37025', 'A3AFB73F065DA381', '45A0A98E6B43DCDF', '7FD74197CAB0ED1C', '920674678A535DC7', '386A97F23FE00DFF', '073591D56E5FB97D', '11FCA1ABE7503115', '3CC18C351D2F3D3B', 'AB5ED67F4B81A024', 'A1B370E17B570EC5', 'CC7A432B9DDC131D', '0B28343ED5F86A9A', 'C35ABF268FCB08A3', '3D16F2A00A88B45F', '08152E9185236708', 'ECA008BBF999C9DE', 'BB549502AB2C1AFB', '2E185A6F70FC104E', '5530B9A31955ED8B', 'B8F8AD2DBF1226F3', '0B74BB443E791846', 'E7EAEB7775C6FF9D', '38CD5BEB83A10949', '9F989C60B6045FEE', 'F63DF45127E2FA23', '3F0C6A7DFF63AB34', '36CA7DB96600D6BE', 'BCAA6B147AF2621E', 'CB84E662169BA0DF',
  1147. '497F4B224093229D', '37D4B24EE7FF28E7', '8B517D62554774A6', 'E34FE5AEFA4D798D', '85F99642BD9F2505', '1F6EE5A34C6DC5FA', 'D152E21A5E58BA94', '9CA1D6BC180201E4', '3D1D610BF080F355', '9D540F4B1ADF16B2', '413F0CF75960608C', '97689572FF8AE161', '30B287B328525255', '7B396A12DAB2E67C', '3B7867F3C16FF33E', 'A956BC99B4126A43', 'A8CE493ABCF95C02', '82158F47205BA3CB', 'F4BC1993A777E62C', '1703786B5945840C', 'D005228533E6F5EA', 'E4A42CC57A571F44', 'C4E95924BF7F82B3', '80EF3AE803D178DC', 'D8C405F6759361D1', '80B5ECCF06E95383', '6DBD8FC81E4BEB6A', 'AC305B5880061E5E', '54659114A08EE52B', 'FC1285CA30E06B24',
  1148. '5FCA2A8523983788', '09AD2AD3630656D9', 'BFAF8BE5DFDC6C53', '06BE62AEBB8EC40E', 'B0E68E7A21762CEE', '6CC82CFBBDDD7AB6', '30CC28851C745E19', '901A7611BB5D9F44', 'D76E0E705F830FFA', '0F13602C99462F16', '43B72D9F1963D646', '9FB0769CCB26AE45', '9B12999075597D2F', 'C62395CF5A3FFAEF', '6C9C943CC52D8325', 'F5B48F8384BCA968', '4314CCE0E9F230E6', '0368A40BDA81480A', '3DEC51FD2C223A7E', '71989114D1B74DC7' ]
  1149. // @NoUseNewKeyEx return 1;//???????????????????????1
  1150. // @NoSupNewKeyEx return 2;//???????????????????????2
  1151. var mEncInString = EncInString[myrnd]
  1152. var mEncOutString = EncOutString[myrnd]
  1153. for (n = 0; n < 255; n++) {
  1154. var DevicePath = this.FindPort(n)// ??????????????��??
  1155. if (this.lasterror != 0) return this.lasterror
  1156. var outString = this.EncString_New(mEncInString, DevicePath)
  1157. if ((this.lasterror == 0) && (outString.toUpperCase() == mEncOutString.toUpperCase())) return 0
  1158. }
  1159. return -92
  1160. }
  1161. }
  1162. // vid,pid
  1163. mSoftKey.VID = 0x3689
  1164. mSoftKey.PID = 0x8762
  1165. mSoftKey.PID_NEW = 0X2020
  1166. mSoftKey.VID_NEW = 0X3689
  1167. mSoftKey.PID_NEW_2 = 0X2020
  1168. mSoftKey.VID_NEW_2 = 0X2020
  1169. export default mSoftKey