|
@@ -0,0 +1,1369 @@
|
|
|
+// JScript source code
|
|
|
+
|
|
|
+var HID = require('node-hid')
|
|
|
+const sm3 = require('sm3')
|
|
|
+
|
|
|
+var GETVERSION = 0x01
|
|
|
+var GETID = 0x02
|
|
|
+var GETVEREX = 0x05
|
|
|
+var CAL_TEA = 0x08
|
|
|
+var SET_TEAKEY = 0x09
|
|
|
+var READBYTE = 0x10
|
|
|
+var WRITEBYTE = 0x11
|
|
|
+var YTREADBUF = 0x12
|
|
|
+var YTWRITEBUF = 0x13
|
|
|
+var MYRESET = 0x20
|
|
|
+var YTREBOOT = 0x24
|
|
|
+var SET_ECC_PARA = 0x30
|
|
|
+var GET_ECC_PARA = 0x31
|
|
|
+var SET_ECC_KEY = 0x32
|
|
|
+var GET_ECC_KEY = 0x33
|
|
|
+var MYENC = 0x34
|
|
|
+var MYDEC = 0X35
|
|
|
+var SET_PIN = 0X36
|
|
|
+var GEN_KEYPAIR = 0x37
|
|
|
+var YTVERIFY = 0x52
|
|
|
+var GET_CHIPID = 0x53
|
|
|
+
|
|
|
+// errcode
|
|
|
+var FAILEDGENKEYPAIR = -21
|
|
|
+var FAILENC = -22
|
|
|
+var FAILDEC = -23
|
|
|
+var FAILPINPWD = -24
|
|
|
+var USBStatusFail = -50
|
|
|
+var ERR_SET_REPORT = -94
|
|
|
+var ERR_GET_REPORT = -93
|
|
|
+
|
|
|
+var MAX_LEN = 2031
|
|
|
+
|
|
|
+var SM2_ADDBYTE = 97//
|
|
|
+var MAX_ENCLEN = 128 //
|
|
|
+var MAX_DECLEN = (MAX_ENCLEN + SM2_ADDBYTE) //
|
|
|
+var SM2_USENAME_LEN = 80//
|
|
|
+
|
|
|
+var ECC_MAXLEN = 32
|
|
|
+var PIN_LEN = 16
|
|
|
+
|
|
|
+var MAX_TRANSE_LEN = 21
|
|
|
+var SM2_MAX_TRANSE_LEN = 255
|
|
|
+
|
|
|
+var ID_LEN = 16
|
|
|
+
|
|
|
+var mSoftKey = class SoftKey {
|
|
|
+ SoftKey () {
|
|
|
+ // connection object
|
|
|
+ SoftKey.connection = null
|
|
|
+ }
|
|
|
+
|
|
|
+ GetLastError () {
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ StrEnc (InString, Key) {
|
|
|
+ var n; var m
|
|
|
+ var nlen
|
|
|
+
|
|
|
+ var b = Buffer.from(InString)
|
|
|
+ var zero_buf = Buffer.from([0])
|
|
|
+ b = Buffer.concat([b, zero_buf])
|
|
|
+ nlen = b.length
|
|
|
+ if (b.length < 8) {
|
|
|
+ nlen = 8
|
|
|
+ }
|
|
|
+
|
|
|
+ var outb = Buffer.alloc(nlen)
|
|
|
+ var inb = Buffer.alloc(nlen)
|
|
|
+ b.copy(inb)// ???????8?????0????????????????0
|
|
|
+ b.copy(outb)
|
|
|
+
|
|
|
+ for (n = 0; n <= (nlen - 8); n = n + 8) {
|
|
|
+ var tmpoutb = this.sub_EnCode(inb, n, Key)
|
|
|
+ for (m = 0; m < 8; m++) {
|
|
|
+ outb[m + n] = tmpoutb[m]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return outb.toString('hex')
|
|
|
+ }
|
|
|
+
|
|
|
+ StrDec (InString, Key)//
|
|
|
+ {
|
|
|
+ var n, m
|
|
|
+ var inb = new Buffer(InString, 'hex')
|
|
|
+ var outb = Buffer.alloc(inb.length)
|
|
|
+ inb.copy(outb)
|
|
|
+
|
|
|
+ for (n = 0; n <= inb.length - 8; n = n + 8) {
|
|
|
+ var tmpoutb = this.sub_DeCode(inb, n, Key)
|
|
|
+ for (m = 0; m < 8; m++) {
|
|
|
+ outb[m + n] = tmpoutb[m]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return outb.toString()
|
|
|
+ }
|
|
|
+
|
|
|
+ EnCode (inb, Key) {
|
|
|
+ this.sub_EnCode(inb, 0, Key)
|
|
|
+ }
|
|
|
+
|
|
|
+ sub_EnCode (inb, pos, Key) {
|
|
|
+ var cnDelta, y, z, a, b, c, d
|
|
|
+ var outb = new Uint8Array(8)
|
|
|
+ var n, i, nlen
|
|
|
+ var sum
|
|
|
+ var temp, temp_1
|
|
|
+
|
|
|
+ var buf = new Array(16)
|
|
|
+ var temp_string
|
|
|
+
|
|
|
+ cnDelta = 2654435769
|
|
|
+ sum = 0
|
|
|
+
|
|
|
+ nlen = Key.length
|
|
|
+ i = 0
|
|
|
+ for (n = 1; n <= nlen; n = n + 2) {
|
|
|
+ temp_string = Key.substring(n - 1, n - 1 + 2)
|
|
|
+ buf[i] = this.HexToInt(temp_string)
|
|
|
+ i = i + 1
|
|
|
+ }
|
|
|
+ a = 0; b = 0; c = 0; d = 0
|
|
|
+ for (n = 0; n <= 3; n++) {
|
|
|
+ a = (buf[n] << (n * 8)) | a
|
|
|
+ b = (buf[n + 4] << (n * 8)) | b
|
|
|
+ c = (buf[n + 4 + 4] << (n * 8)) | c
|
|
|
+ d = (buf[n + 4 + 4 + 4] << (n * 8)) | d
|
|
|
+ }
|
|
|
+
|
|
|
+ y = 0
|
|
|
+ z = 0
|
|
|
+ for (n = 0; n <= 3; n++) {
|
|
|
+ y = (inb[n + pos] << (n * 8)) | y
|
|
|
+ z = (inb[n + 4 + pos] << (n * 8)) | z
|
|
|
+ }
|
|
|
+
|
|
|
+ n = 32
|
|
|
+
|
|
|
+ while (n > 0) {
|
|
|
+ sum = cnDelta + sum
|
|
|
+
|
|
|
+ temp = (z << 4) & 0xFFFFFFFF
|
|
|
+
|
|
|
+ temp = (temp + a) & 0xFFFFFFFF
|
|
|
+ temp_1 = (z + sum) & 0xFFFFFFFF
|
|
|
+ temp = (temp ^ temp_1) & 0xFFFFFFFF
|
|
|
+ temp_1 = (z >>> 5) & 0xFFFFFFFF
|
|
|
+ temp_1 = (temp_1 + b) & 0xFFFFFFFF
|
|
|
+ temp = (temp ^ temp_1) & 0xFFFFFFFF
|
|
|
+ temp = (temp + y) & 0xFFFFFFFF
|
|
|
+ y = temp & 0xFFFFFFFF
|
|
|
+ // y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
|
|
|
+
|
|
|
+ temp = (y << 4) & 0xFFFFFFFF
|
|
|
+ temp = (temp + c) & 0xFFFFFFFF
|
|
|
+ temp_1 = (y + sum) & 0xFFFFFFFF
|
|
|
+ temp = (temp ^ temp_1) & 0xFFFFFFFF
|
|
|
+ temp_1 = (y >>> 5) & 0xFFFFFFFF
|
|
|
+ temp_1 = (temp_1 + d) & 0xFFFFFFFF
|
|
|
+ temp = (temp ^ temp_1) & 0xFFFFFFFF
|
|
|
+ temp = (z + temp) & 0xFFFFFFFF
|
|
|
+ z = temp & 0xFFFFFFFF
|
|
|
+ // z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
|
|
|
+
|
|
|
+ n = n - 1
|
|
|
+ }
|
|
|
+
|
|
|
+ for (n = 0; n <= 3; n++) {
|
|
|
+ outb[n] = ((y >>> (n * 8)) & 255)
|
|
|
+ outb[n + 4] = ((z >>> (n * 8)) & 255)
|
|
|
+ }
|
|
|
+ return outb
|
|
|
+ }
|
|
|
+
|
|
|
+ DeCode () {
|
|
|
+ sub_DeCode(inb, 0, Key)
|
|
|
+ }
|
|
|
+
|
|
|
+ sub_DeCode (inb, pos, Key) {
|
|
|
+ var cnDelta, y, z, a, b, c, d
|
|
|
+ var outb = new Uint8Array(8)
|
|
|
+ var n, i, nlen
|
|
|
+ var sum
|
|
|
+ var temp, temp_1
|
|
|
+
|
|
|
+ var buf = new Array(16)
|
|
|
+ var temp_string
|
|
|
+
|
|
|
+ cnDelta = 2654435769
|
|
|
+ sum = 3337565984
|
|
|
+
|
|
|
+ nlen = Key.length
|
|
|
+ i = 0
|
|
|
+ for (n = 1; n <= nlen; n = n + 2) {
|
|
|
+ temp_ = Key.substring(n - 1, n - 1 + 2)
|
|
|
+ buf[i] = this.HexToInt(temp_string)
|
|
|
+ i = i + 1
|
|
|
+ }
|
|
|
+ a = 0; b = 0; c = 0; d = 0
|
|
|
+ for (n = 0; n <= 3; n++) {
|
|
|
+ a = (buf[n] << (n * 8)) | a
|
|
|
+ b = (buf[n + 4] << (n * 8)) | b
|
|
|
+ c = (buf[n + 4 + 4] << (n * 8)) | c
|
|
|
+ d = (buf[n + 4 + 4 + 4] << (n * 8)) | d
|
|
|
+ }
|
|
|
+
|
|
|
+ y = 0
|
|
|
+ z = 0
|
|
|
+ for (n = 0; n <= 3; n++) {
|
|
|
+ y = (inb[n + pos] << (n * 8)) | y
|
|
|
+ z = (inb[n + 4 + pos] << (n * 8)) | z
|
|
|
+ }
|
|
|
+
|
|
|
+ n = 32
|
|
|
+
|
|
|
+ while (n > 0) {
|
|
|
+ temp = (y << 4) & 0xFFFFFFFF
|
|
|
+ temp = (temp + c) & 0xFFFFFFFF
|
|
|
+ temp_1 = (y + sum) & 0xFFFFFFFF
|
|
|
+ temp = (temp ^ temp_1) & 0xFFFFFFFF
|
|
|
+ temp_1 = (y >>> 5) & 0xFFFFFFFF
|
|
|
+ temp_1 = (temp_1 + d) & 0xFFFFFFFF
|
|
|
+ temp = (temp ^ temp_1) & 0xFFFFFFFF
|
|
|
+ temp = (z - temp) & 0xFFFFFFFF
|
|
|
+ z = temp & 0xFFFFFFFF
|
|
|
+ // z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
|
|
|
+
|
|
|
+ temp = (z << 4) & 0xFFFFFFFF
|
|
|
+ temp = (temp + a) & 0xFFFFFFFF
|
|
|
+ temp_1 = (z + sum) & 0xFFFFFFFF
|
|
|
+ temp = (temp ^ temp_1) & 0xFFFFFFFF
|
|
|
+ temp_1 = (z >>> 5) & 0xFFFFFFFF
|
|
|
+ temp_1 = (temp_1 + b) & 0xFFFFFFFF
|
|
|
+ temp = (temp ^ temp_1) & 0xFFFFFFFF
|
|
|
+ temp = (y - temp) & 0xFFFFFFFF
|
|
|
+ y = temp & 0xFFFFFFFF
|
|
|
+ // y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
|
|
|
+
|
|
|
+ sum = sum - cnDelta
|
|
|
+ n = n - 1
|
|
|
+ }
|
|
|
+
|
|
|
+ for (n = 0; n <= 3; n++) {
|
|
|
+ outb[n] = ((y >>> (n * 8)) & 255)
|
|
|
+ outb[n + 4] = ((z >>> (n * 8)) & 255)
|
|
|
+ }
|
|
|
+ return outb
|
|
|
+ }
|
|
|
+
|
|
|
+ MacthUKeyID (mDevices) {
|
|
|
+ if ((mDevices.vendorId == mSoftKey.VID && mDevices.productId == mSoftKey.PID) ||
|
|
|
+ (mDevices.vendorId == mSoftKey.VID_NEW && mDevices.productId == mSoftKey.PID_NEW) ||
|
|
|
+ (mDevices.vendorId == mSoftKey.VID_NEW_2 && mDevices.productId == mSoftKey.PID_NEW_2)) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ /// //////////////////
|
|
|
+ AddZero (InKey) {
|
|
|
+ var nlen
|
|
|
+ var n
|
|
|
+ nlen = InKey.length
|
|
|
+ for (n = nlen; n <= 7; n++) {
|
|
|
+ InKey = '0' + InKey
|
|
|
+ }
|
|
|
+ return InKey
|
|
|
+ }
|
|
|
+
|
|
|
+ myconvert (HKey, LKey) {
|
|
|
+ HKey = this.AddZero(HKey)
|
|
|
+ LKey = this.AddZero(LKey)
|
|
|
+ var out_data = new Uint8Array(8)
|
|
|
+ var n
|
|
|
+ for (n = 0; n <= 3; n++) {
|
|
|
+ out_data[n] = this.HexToInt(HKey.substring(n * 2, n * 2 + 2))
|
|
|
+ }
|
|
|
+ for (n = 0; n <= 3; n++) {
|
|
|
+ out_data[n + 4] = this.HexToInt(LKey.substring(n * 2, n * 2 + 2))
|
|
|
+ }
|
|
|
+ return out_data
|
|
|
+ }
|
|
|
+
|
|
|
+ /// /bin2hex & hex2bin
|
|
|
+ ByteArrayToHexString (Inb, len) {
|
|
|
+ var outstring = ''
|
|
|
+ for (var n = 0; n <= len - 1; n++) {
|
|
|
+ outstring = outstring + this.myhex(Inb[n])
|
|
|
+ }
|
|
|
+ return outstring
|
|
|
+ }
|
|
|
+
|
|
|
+ HexStringToByteArray (InString) {
|
|
|
+ var nlen
|
|
|
+ var retutn_len
|
|
|
+ var n, i
|
|
|
+ var b
|
|
|
+ var temp
|
|
|
+ nlen = InString.length
|
|
|
+ if (nlen < 16) retutn_len = 16
|
|
|
+ retutn_len = nlen / 2
|
|
|
+ b = new Uint8Array(retutn_len)
|
|
|
+ i = 0
|
|
|
+ for (n = 0; n < nlen; n = n + 2) {
|
|
|
+ temp = InString.substring(n, n + 2)
|
|
|
+ b[i] = this.HexToInt(temp)
|
|
|
+ i = i + 1
|
|
|
+ }
|
|
|
+ return b
|
|
|
+ }
|
|
|
+ /// /////
|
|
|
+
|
|
|
+ // decimal to hex && hex2dec
|
|
|
+ myhex (value) {
|
|
|
+ if (value < 16) { return '0' + value.toString(16) }
|
|
|
+ return value.toString(16)
|
|
|
+ };
|
|
|
+
|
|
|
+ HexToInt (s) {
|
|
|
+ var hexch = '0123456789ABCDEF'
|
|
|
+ var i, j
|
|
|
+ var r, n, k
|
|
|
+ var ch
|
|
|
+ s = s.toUpperCase()
|
|
|
+
|
|
|
+ k = 1; r = 0
|
|
|
+ for (i = s.length; i > 0; i--) {
|
|
|
+ ch = s.substring(i - 1, i - 1 + 1)
|
|
|
+ n = 0
|
|
|
+ for (j = 0; j < 16; j++) {
|
|
|
+ if (ch == hexch.substring(j, j + 1)) {
|
|
|
+ n = j
|
|
|
+ }
|
|
|
+ }
|
|
|
+ r += (n * k)
|
|
|
+ k *= 16
|
|
|
+ }
|
|
|
+ return r
|
|
|
+ };
|
|
|
+ /// /////////////
|
|
|
+
|
|
|
+ /// //////////// send cmd only ,no carry data
|
|
|
+ SendNoWithData (CmdFlag) {
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ this.SendWithData(CmdFlag, array_in)
|
|
|
+ return this.lasterror
|
|
|
+ };
|
|
|
+ /// ////////////////////////
|
|
|
+ /* SendWithDataNoErr(CmdFlag,array_in,KeyPath) {
|
|
|
+
|
|
|
+ this.lasterror=0;
|
|
|
+ var featureReport = [2, 0];
|
|
|
+
|
|
|
+ featureReport[1] = CmdFlag;
|
|
|
+
|
|
|
+ for (var i = 1; i < array_in.length; i++) {
|
|
|
+ featureReport[i + 1] =array_in[i];
|
|
|
+ }
|
|
|
+ if(KeyPath==null)
|
|
|
+ {
|
|
|
+ this.lasterror= -92;
|
|
|
+ return array_out;
|
|
|
+ }
|
|
|
+ this.connection = new HID.HID(KeyPath)
|
|
|
+ if(this.connection==null)
|
|
|
+ {
|
|
|
+ this.lasterror= -92;
|
|
|
+ return array_out;
|
|
|
+ }
|
|
|
+ var Outlen=this.connection.sendFeatureReport( featureReport);
|
|
|
+ if(Outlen<2) {this.connection.close();this.lasterror= ERR_SET_REPORT;return undefined;}
|
|
|
+ var array_out=this.connection.getFeatureReport(1,SM2_MAX_TRANSE_LEN) ;
|
|
|
+ this.connection.close();
|
|
|
+ if(array_out.length<1){this.lasterror=ERR_GET_REPORT; return undefined;}
|
|
|
+
|
|
|
+ return array_out;
|
|
|
+
|
|
|
+} */
|
|
|
+ /// ////////send cmd and data
|
|
|
+ SendWithDataNoErr (CmdFlag, array_in, KeyPath) {
|
|
|
+ this.lasterror = 0
|
|
|
+ var featureReport = [2]
|
|
|
+ for (var n = 1; n <= SM2_MAX_TRANSE_LEN + 1; n++) {
|
|
|
+ featureReport[n] = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ featureReport[1] = CmdFlag
|
|
|
+
|
|
|
+ for (var i = 1; i < array_in.length; i++) {
|
|
|
+ featureReport[i + 1] = array_in[i]
|
|
|
+ }
|
|
|
+ if (KeyPath == null) {
|
|
|
+ this.lasterror = -92
|
|
|
+ return array_out
|
|
|
+ }
|
|
|
+ this.connection = new HID.HID(KeyPath)
|
|
|
+ if (this.connection == null) {
|
|
|
+ this.lasterror = -92
|
|
|
+ return array_out
|
|
|
+ }
|
|
|
+ var Outlen = this.connection.sendFeatureReport(featureReport)
|
|
|
+ if (Outlen < 2) { this.connection.close(); this.lasterror = ERR_SET_REPORT; return undefined }
|
|
|
+ var array_out = this.connection.getFeatureReport(1, 510)
|
|
|
+ this.connection.close()
|
|
|
+ if (array_out.length < 1) { this.lasterror = ERR_GET_REPORT; return undefined }
|
|
|
+
|
|
|
+ return array_out
|
|
|
+ }
|
|
|
+
|
|
|
+ SendWithData (CmdFlag, array_in, KeyPath) {
|
|
|
+ var array_out = this.SendWithDataNoErr(CmdFlag, array_in, KeyPath)
|
|
|
+
|
|
|
+ if (array_out[0] != 0) {
|
|
|
+ this.lasterror = array_out[0] - 256
|
|
|
+ } else {
|
|
|
+ this.lasterror = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ return array_out
|
|
|
+ }
|
|
|
+ /// ////////////
|
|
|
+ GetOneByteDataFromUsbKey (cmd, KeyPath) {
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ var array_out
|
|
|
+ array_out = this.SendWithDataNoErr(cmd, array_in, KeyPath)
|
|
|
+ if (this.lasterror) return undefined
|
|
|
+ return array_out[0]
|
|
|
+ }
|
|
|
+ /// /////
|
|
|
+
|
|
|
+ FindPort (start) {
|
|
|
+ this.lasterror = 0
|
|
|
+ var KeyPath = ''
|
|
|
+ var count = 0
|
|
|
+ var devices = HID.devices()
|
|
|
+ devices.forEach(mDevice => {
|
|
|
+ if (this.MacthUKeyID(mDevice)) {
|
|
|
+ if (count == start) {
|
|
|
+ KeyPath = mDevice.path
|
|
|
+ return KeyPath
|
|
|
+ }
|
|
|
+ count++
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (KeyPath != '') {
|
|
|
+ this.lasterror = 0
|
|
|
+ } else {
|
|
|
+ this.lasterror = -92
|
|
|
+ }
|
|
|
+ return KeyPath
|
|
|
+ }
|
|
|
+
|
|
|
+ /// /////////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ NT_GetIDVersionEx (KeyPath) {
|
|
|
+ return this.GetOneByteDataFromUsbKey(5, KeyPath)
|
|
|
+ };
|
|
|
+
|
|
|
+ NT_GetIDVersion (KeyPath) {
|
|
|
+ return this.GetOneByteDataFromUsbKey(1, KeyPath)
|
|
|
+ };
|
|
|
+ /// //
|
|
|
+
|
|
|
+ GetID (KeyPath) {
|
|
|
+ var IDInfo = {
|
|
|
+ ID_1: '',
|
|
|
+ ID_2: ''
|
|
|
+ }
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ var array_out
|
|
|
+ var t1 = new Buffer.alloc(4)
|
|
|
+ var t2 = new Buffer.alloc(4)
|
|
|
+ array_out = this.SendWithDataNoErr(2, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) { return '' }
|
|
|
+ t1[0] = array_out[0]; t1[1] = array_out[1]; t1[2] = array_out[2]; t1[3] = array_out[3]
|
|
|
+ t2[0] = array_out[4]; t2[1] = array_out[5]; t2[2] = array_out[6]; t2[3] = array_out[7]
|
|
|
+ IDInfo.ID_1 = t1.toString('hex')
|
|
|
+ IDInfo.ID_2 = t2.toString('hex')
|
|
|
+ return IDInfo
|
|
|
+ }
|
|
|
+
|
|
|
+ GetChipID (KeyPath) {
|
|
|
+ var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
|
|
|
+ var array_out
|
|
|
+
|
|
|
+ var OutChipID = ''; var outb = new Uint8Array(ID_LEN)
|
|
|
+
|
|
|
+ array_out = this.SendWithDataNoErr(GET_CHIPID, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) { return '' }
|
|
|
+ if (array_out[0] != 0x20) {
|
|
|
+ this.lasterror = USBStatusFail
|
|
|
+ return OutChipID
|
|
|
+ }
|
|
|
+
|
|
|
+ outb = array_out.slice(1, ID_LEN + 1)
|
|
|
+
|
|
|
+ OutChipID = this.ByteArrayToHexString(outb, 16)
|
|
|
+ OutChipID = OutChipID.toUpperCase()
|
|
|
+ return OutChipID
|
|
|
+ };
|
|
|
+ /// /////
|
|
|
+
|
|
|
+ /// //
|
|
|
+ FindPort_2 (start, in_data, verf_data) {
|
|
|
+ var n
|
|
|
+ var count = 0
|
|
|
+ var out_data = 0
|
|
|
+ for (n = 0; n < 256; n++) {
|
|
|
+ var KeyPath = this.FindPort(n)
|
|
|
+ if (this.lasterror != 0) return null
|
|
|
+ out_data = this.sWriteEx(in_data, KeyPath)
|
|
|
+ if (this.lasterror != 0) return null
|
|
|
+ if (out_data == verf_data) {
|
|
|
+ if (start == count) return KeyPath
|
|
|
+ count++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null
|
|
|
+ };
|
|
|
+
|
|
|
+ SetWritePassword (W_HKey, W_LKey, new_HKey, new_LKey, KeyPath) {
|
|
|
+ var address
|
|
|
+ var ary1 = this.myconvert(W_HKey, W_LKey)
|
|
|
+ var ary2 = this.myconvert(new_HKey, new_LKey)
|
|
|
+ address = 504
|
|
|
+
|
|
|
+ this.lasterror = this.Sub_WriteByte(ary2, address, 8, ary1, 0, KeyPath)
|
|
|
+
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ SetReadPassword (W_HKey, W_LKey, new_HKey, new_LKey, KeyPath) {
|
|
|
+ var address
|
|
|
+ var ary1 = this.myconvert(W_HKey, W_LKey)
|
|
|
+ var ary2 = this.myconvert(new_HKey, new_LKey)
|
|
|
+ address = 496
|
|
|
+
|
|
|
+ this.lasterror = this.Sub_WriteByte(ary2, address, 8, ary1, 0, KeyPath)
|
|
|
+
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_SetCal (cmd, indata, IsHi, pos, KeyPath) {
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ var n
|
|
|
+ array_in[1] = IsHi
|
|
|
+ for (n = 0; n < 8; n++) {
|
|
|
+ array_in[2 + n] = indata[n + pos]
|
|
|
+ }
|
|
|
+
|
|
|
+ var array_out = this.SendWithData(cmd, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ if (array_out[0] != 0) {
|
|
|
+ this.lasterror = -82
|
|
|
+ }
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ Sub_SetCal (cmd, Key, KeyPath) {
|
|
|
+ var KeyBuf = this.HexStringToByteArray(Key)
|
|
|
+ this.lasterror = this.NT_SetCal(cmd, KeyBuf, 0, 8, KeyPath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ return this.NT_SetCal(cmd, KeyBuf, 1, 0, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ SetCal_2 (Key, KeyPath) {
|
|
|
+ return this.Sub_SetCal(SET_TEAKEY, Key, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ SetCal_New (Key, KeyPath) {
|
|
|
+ return this.Sub_SetCal(13, Key, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ Sub_EncString (cmd, InString, KeyPath) {
|
|
|
+ var n; var m
|
|
|
+ var nlen
|
|
|
+
|
|
|
+ var b = Buffer.from(InString)
|
|
|
+ var zero_buf = Buffer.from([0])
|
|
|
+ b = Buffer.concat([b, zero_buf])
|
|
|
+ nlen = b.length
|
|
|
+ if (b.length < 8) {
|
|
|
+ nlen = 8
|
|
|
+ }
|
|
|
+
|
|
|
+ var outb = Buffer.alloc(nlen)
|
|
|
+ var inb = Buffer.alloc(nlen)
|
|
|
+ b.copy(inb)// ???????8?????0????????????????0
|
|
|
+ b.copy(outb)
|
|
|
+
|
|
|
+ for (n = 0; n <= (nlen - 8); n = n + 8) {
|
|
|
+ var tmpoutb = this.NT_Cal(cmd, inb, n, KeyPath)
|
|
|
+ for (m = 0; m < 8; m++) {
|
|
|
+ outb[m + n] = tmpoutb[m]
|
|
|
+ }
|
|
|
+ if (this.lasterror != 0) ''
|
|
|
+ }
|
|
|
+
|
|
|
+ return outb.toString('hex')
|
|
|
+ }
|
|
|
+
|
|
|
+ EncString (InString, KeyPath) {
|
|
|
+ return this.Sub_EncString(8, InString, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ EncString_New (InString, KeyPath) {
|
|
|
+ return this.Sub_EncString(12, InString, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_Cal (cmd, InBuf, pos, KeyPath) {
|
|
|
+ var n
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ var outbuf = new Uint8Array(8)
|
|
|
+ for (n = 1; n <= 8; n++) {
|
|
|
+ array_in[n] = InBuf[n - 1 + pos]
|
|
|
+ }
|
|
|
+ var array_out = this.SendWithDataNoErr(cmd, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return undefined
|
|
|
+ for (n = 0; n < 8; n++) {
|
|
|
+ outbuf[n + pos] = array_out[n]
|
|
|
+ }
|
|
|
+ if (array_out[8] != 0x55) {
|
|
|
+ this.lasterror = -20
|
|
|
+ }
|
|
|
+ return outbuf
|
|
|
+ }
|
|
|
+
|
|
|
+ Cal (Inbuf, KeyPath) {
|
|
|
+ return this.NT_Cal(8, Inbuf, 0, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ Cal_New (Inbuf, KeyPath) {
|
|
|
+ return this.NT_Cal(12, Inbuf, 0, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ SimpleCalData (cmd, in_data, KeyPath) {
|
|
|
+ var t1
|
|
|
+ var t2
|
|
|
+ var t3
|
|
|
+ var t4
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ array_in[1] = (in_data & 255)
|
|
|
+ array_in[2] = ((in_data >> 8) & 255)
|
|
|
+ array_in[3] = ((in_data >> 16) & 255)
|
|
|
+ array_in[4] = ((in_data >> 24) & 255)
|
|
|
+
|
|
|
+ var array_out
|
|
|
+ array_out = this.SendWithDataNoErr(cmd, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) { return 0 }
|
|
|
+ t1 = array_out[0]
|
|
|
+ t2 = array_out[1]
|
|
|
+ t3 = array_out[2]
|
|
|
+ t4 = array_out[3]
|
|
|
+
|
|
|
+ return t1 | (t2 << 8) | (t3 << 16) | (t4 << 24)
|
|
|
+ }
|
|
|
+
|
|
|
+ sWriteEx (in_data, KeyPath) {
|
|
|
+ return this.SimpleCalData(0x03, in_data, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ sWrite_2Ex (in_data, KeyPath) {
|
|
|
+ return this.SimpleCalData(0x04, in_data, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ /// //////////////////
|
|
|
+ Sub_WriteByte (indata, address, nlen, password, pos, KeyPath) {
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ var addr_l
|
|
|
+ var addr_h
|
|
|
+ var n
|
|
|
+ if ((address + nlen - 1) > (MAX_LEN + 17) || (address < 0)) return -81
|
|
|
+ addr_h = (address >> 8) * 2
|
|
|
+ addr_l = address & 255
|
|
|
+
|
|
|
+ array_in[1] = addr_h
|
|
|
+ array_in[2] = addr_l
|
|
|
+ array_in[3] = nlen
|
|
|
+
|
|
|
+ for (n = 0; n <= 7; n++) {
|
|
|
+ array_in[4 + n] = password[n]
|
|
|
+ }
|
|
|
+ for (n = 0; n < nlen; n++) {
|
|
|
+ array_in[12 + n] = indata[n + pos]
|
|
|
+ }
|
|
|
+
|
|
|
+ var array_out = this.SendWithDataNoErr(0x13, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ if (array_out[0] != 0) {
|
|
|
+ this.lasterror = -82
|
|
|
+ }
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+ /// ///////////
|
|
|
+
|
|
|
+ Sub_ReadByte (address, nlen, password, KeyPath) {
|
|
|
+ var outData = new Uint8Array(nlen)
|
|
|
+ var array_out
|
|
|
+ var ret
|
|
|
+ if (nlen > MAX_TRANSE_LEN) {
|
|
|
+ this.lasterror = ERR_OVER_SEC_MAX_LEN
|
|
|
+ return outData
|
|
|
+ }
|
|
|
+ if ((address + nlen > MAX_LEN)) {
|
|
|
+ this.lasterror == ERR_OVER_SEC_MAX_LEN
|
|
|
+ return outData
|
|
|
+ }
|
|
|
+
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ var addr_l
|
|
|
+ var addr_h
|
|
|
+ var n
|
|
|
+
|
|
|
+ addr_h = (address >> 8) * 2
|
|
|
+ addr_l = address & 255
|
|
|
+
|
|
|
+ array_in[1] = addr_h
|
|
|
+ array_in[2] = addr_l
|
|
|
+ array_in[3] = nlen
|
|
|
+
|
|
|
+ for (n = 0; n <= 7; n++) {
|
|
|
+ array_in[4 + n] = password[n]
|
|
|
+ }
|
|
|
+
|
|
|
+ array_out = this.SendWithDataNoErr(0x12, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return undefined
|
|
|
+ if (array_out[0] != 0) {
|
|
|
+ this.lasterror = -82; return outData
|
|
|
+ }
|
|
|
+ for (n = 0; n < (nlen); n++) {
|
|
|
+ outData[n] = array_out[n + 1]
|
|
|
+ }
|
|
|
+ return outData
|
|
|
+ }
|
|
|
+
|
|
|
+ /// //////////////////////////
|
|
|
+ YWriteEx (indata, address, nlen, HKey, LKey, KeyPath) {
|
|
|
+ var ret = 0
|
|
|
+ var n, trashLen = 16
|
|
|
+
|
|
|
+ if ((address + nlen - 1 > MAX_LEN) || (address < 0)) return -81
|
|
|
+
|
|
|
+ trashLen = trashLen - 8
|
|
|
+
|
|
|
+ var password = this.myconvert(HKey, LKey)
|
|
|
+ var tmplen
|
|
|
+ var pos = 0
|
|
|
+ while (nlen > 0) {
|
|
|
+ if (nlen > trashLen) { tmplen = trashLen } else { tmplen = nlen }
|
|
|
+ this.lasterror = this.Sub_WriteByte(indata, address + pos, tmplen, password, pos, KeyPath)
|
|
|
+ if (this.lasterror != 0) { return this.lasterror }
|
|
|
+ nlen = nlen - trashLen
|
|
|
+ pos = pos + trashLen
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ /// ////////////////////////////
|
|
|
+ YWriteString (InString, Address, HKey, LKey, KeyPath) {
|
|
|
+ var Buf = Buffer.from(InString)
|
|
|
+ this.YWriteEx(Buf, Address, Buf.length, HKey, LKey, KeyPath)
|
|
|
+ if (this.lasterror < 0) return this.lasterror
|
|
|
+ return Buf.length
|
|
|
+ }
|
|
|
+
|
|
|
+ /// ////////////
|
|
|
+ YReadEx (address, nlen, HKey, LKey, KeyPath) {
|
|
|
+ var ret = 0
|
|
|
+ var password = new Uint8Array(8)
|
|
|
+ var n, trashLen = 16
|
|
|
+ var OutData = Buffer.alloc(0)
|
|
|
+ var tmp_OutData
|
|
|
+
|
|
|
+ if ((address + nlen - 1 > MAX_LEN) || (address < 0)) return (-81)
|
|
|
+
|
|
|
+ password = this.myconvert(HKey, LKey)
|
|
|
+ var tmplen
|
|
|
+ var pos = 0
|
|
|
+ while (nlen > 0) {
|
|
|
+ if (nlen > trashLen) { tmplen = trashLen } else { tmplen = nlen }
|
|
|
+ tmp_OutData = this.Sub_ReadByte(address + pos, tmplen, password, KeyPath)
|
|
|
+ if (this.lasterror != 0) { return OutData }
|
|
|
+ OutData = Buffer.concat([OutData, tmp_OutData])
|
|
|
+ nlen = nlen - trashLen
|
|
|
+ pos = pos + trashLen
|
|
|
+ }
|
|
|
+
|
|
|
+ return OutData
|
|
|
+ }
|
|
|
+ /// ///////////
|
|
|
+
|
|
|
+ YReadString (Address, nlen, HKey, LKey, KeyPath) {
|
|
|
+ var outData = this.YReadEx(Address, nlen, HKey, LKey, KeyPath)
|
|
|
+
|
|
|
+ return outData.toString()
|
|
|
+ }
|
|
|
+
|
|
|
+ /// ////////////////////////////////////////////////// other api
|
|
|
+ NT_ReSet (KeyPath) {
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ var array_out = this.SendWithDataNoErr(MYRESET, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ if (array_out[0] != 0) {
|
|
|
+ this.lasterror = -82
|
|
|
+ }
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ ReSet (KeyPath) {
|
|
|
+ this.lasterror = this.NT_ReSet(KeyPath)
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ y_setcal (indata, password, KeyPath) {
|
|
|
+ var n
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+
|
|
|
+ array_in[1] = 0
|
|
|
+ array_in[2] = 0
|
|
|
+ array_in[3] = 8
|
|
|
+ for (n = 0; n <= 7; n++) {
|
|
|
+ array_in[4 + n] = password[n]
|
|
|
+ }
|
|
|
+ for (n = 0; n < 8; n++) {
|
|
|
+ array_in[12 + n] = indata[n]
|
|
|
+ }
|
|
|
+ var array_out = this.SendWithDataNoErr(6, array_in, KeyPath)
|
|
|
+ if (this.lasterror) return this.lasterror
|
|
|
+ if (array_out[0] != 0) {
|
|
|
+ this.lasterror = -82
|
|
|
+ }
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ SetCal (HKey, LKey, new_HKey, new_LKey, KeyPath) {
|
|
|
+ var ary1 = this.myconvert(HKey, LKey)
|
|
|
+ var ary2 = this.myconvert(new_HKey, new_LKey)
|
|
|
+
|
|
|
+ this.lasterror = this.y_setcal(ary2, ary1, KeyPath)
|
|
|
+
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_SetID (InBuf, KeyPath) {
|
|
|
+ var n
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ for (n = 1; n <= 8; n++) {
|
|
|
+ array_in[n] = InBuf[n - 2]
|
|
|
+ }
|
|
|
+ var array_out = this.SendWithDataNoErr(7, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ if (array_out[0] != 0) {
|
|
|
+ this.lasterror = -82
|
|
|
+ }
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ SetID (Seed, KeyPath) {
|
|
|
+ var KeyBuf = this.HexStringToByteArray(Seed)
|
|
|
+
|
|
|
+ return this.NT_SetID(KeyBuf, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ GetProduceDate (KeyPath) {
|
|
|
+ var n
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ var OutProduceDate = Buffer.alloc(8)
|
|
|
+ var array_out = this.SendWithDataNoErr(15, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ for (n = 0; n < 8; n++) {
|
|
|
+ OutProduceDate[n] = array_out[n]
|
|
|
+ }
|
|
|
+ return OutProduceDate.toString('hex')
|
|
|
+ }
|
|
|
+
|
|
|
+ SetHidOnly (IsHidOnly, KeyPath) {
|
|
|
+ return this.NT_SetHidOnly(IsHidOnly, KeyPath)
|
|
|
+ }
|
|
|
+ NT_SetHidOnly (IsHidOnly, KeyPath) {
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+
|
|
|
+ if (IsHidOnly) array_in[1] = 0; else array_in[1] = 0xff
|
|
|
+ var array_out = this.SendWithDataNoErr(0x55, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ if (array_out[0] != 0) {
|
|
|
+ return -82
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ SetUReadOnly (KeyPath) {
|
|
|
+ return this.NT_SetUReadOnly(KeyPath)
|
|
|
+ }
|
|
|
+ NT_SetUReadOnly (KeyPath) {
|
|
|
+ var array_in = new Uint8Array(MAX_TRANSE_LEN)
|
|
|
+ var array_out = this.SendWithDataNoErr(0x56, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ if (array_out[0] != 0) {
|
|
|
+ return -82
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_Set_SM2_KeyPair (PriKey, PubKeyX, PubKeyY, sm2_UerName, KeyPath) {
|
|
|
+ var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
|
|
|
+ var n = 0
|
|
|
+
|
|
|
+ for (n = 0; n < ECC_MAXLEN; n++) {
|
|
|
+ array_in[1 + n + ECC_MAXLEN * 0] = PriKey[n]
|
|
|
+ array_in[1 + n + ECC_MAXLEN * 1] = PubKeyX[n]
|
|
|
+ array_in[1 + n + ECC_MAXLEN * 2] = PubKeyY[n]
|
|
|
+ }
|
|
|
+ for (n = 0; n < SM2_USENAME_LEN; n++) {
|
|
|
+ array_in[1 + n + ECC_MAXLEN * 3] = sm2_UerName[n]
|
|
|
+ }
|
|
|
+
|
|
|
+ var array_out = this.SendWithDataNoErr(0x32, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ if (array_out[0] != 0x20) this.lasterror = USBStatusFail
|
|
|
+
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_GenKeyPair (KeyPath) {
|
|
|
+ var KEYPAIR = {
|
|
|
+ PriKey: null,
|
|
|
+ PubKeyX: null,
|
|
|
+ PubKeyY: null
|
|
|
+ }
|
|
|
+ var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
|
|
|
+ var n = 0
|
|
|
+
|
|
|
+ var array_out = this.SendWithDataNoErr(GEN_KEYPAIR, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return undefined
|
|
|
+ if (array_out[0] != 0x20) {
|
|
|
+ this.lasterror = FAILEDGENKEYPAIR; return undefined
|
|
|
+ }
|
|
|
+ KEYPAIR.PriKey = array_out.slice(1, 1 + ECC_MAXLEN)
|
|
|
+ KEYPAIR.PubKeyX = array_out.slice(1 + ECC_MAXLEN, ECC_MAXLEN * 2 + 1)
|
|
|
+ KEYPAIR.PubKeyY = array_out.slice(1 + ECC_MAXLEN * 2, ECC_MAXLEN * 3 + 1)
|
|
|
+ return KEYPAIR
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_Get_SM2_PubKey (KeyPath) {
|
|
|
+ var SM2_PubKeyInfo = {
|
|
|
+ KGx: null,
|
|
|
+ KGy: null,
|
|
|
+ sm2_UerName: null
|
|
|
+ }
|
|
|
+ var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
|
|
|
+ var n = 0
|
|
|
+
|
|
|
+ var array_out = this.SendWithDataNoErr(0x33, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ if (array_out[0] != 0x20) {
|
|
|
+ this.lasterror = USBStatusFail; return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ SM2_PubKeyInfo.KGx = array_out.slice(1, 1 + ECC_MAXLEN * 1)
|
|
|
+ SM2_PubKeyInfo.KGy = array_out.slice(1 + ECC_MAXLEN * 1, 1 + ECC_MAXLEN * 2)
|
|
|
+
|
|
|
+ SM2_PubKeyInfo.sm2_UerName = array_out.slice(1 + ECC_MAXLEN * 2, 1 + ECC_MAXLEN * 2 + SM2_USENAME_LEN)
|
|
|
+
|
|
|
+ return SM2_PubKeyInfo
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_Set_Pin (old_pin, new_pin, KeyPath) {
|
|
|
+ var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
|
|
|
+ var n = 0
|
|
|
+
|
|
|
+ var b_oldpin = Buffer.from(old_pin)
|
|
|
+ var b_newpin = Buffer.from(new_pin)
|
|
|
+ for (n = 0; n < PIN_LEN; n++) {
|
|
|
+ array_in[1 + PIN_LEN * 0 + n] = b_oldpin[n]
|
|
|
+ array_in[1 + PIN_LEN * 1 + n] = b_newpin[n]
|
|
|
+ }
|
|
|
+
|
|
|
+ var array_out = this.SendWithDataNoErr(SET_PIN, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ if (array_out[0] != 0x20) {
|
|
|
+ this.lasterror = USBStatusFail; return this.lasterror
|
|
|
+ }
|
|
|
+ if (array_out[1] != 0x20) {
|
|
|
+ this.lasterror = FAILPINPWD
|
|
|
+ }
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_SM2_Enc (inbuf, inlen, KeyPath) {
|
|
|
+ var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
|
|
|
+ var outbuf = new Uint8Array(inlen + SM2_ADDBYTE)
|
|
|
+ var n = 0
|
|
|
+
|
|
|
+ array_in[1] = inlen
|
|
|
+ for (n = 0; n < inlen; n++) {
|
|
|
+ array_in[2 + n] = inbuf[n]
|
|
|
+ }
|
|
|
+ var array_out = this.SendWithDataNoErr(MYENC, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) {
|
|
|
+ return outbuf
|
|
|
+ }
|
|
|
+ if (array_out[0] != 0x20) {
|
|
|
+ this.lasterror = USBStatusFail
|
|
|
+ return outbuf
|
|
|
+ }
|
|
|
+ if (array_out[1] == 0) {
|
|
|
+ this.lasterror = FAILENC
|
|
|
+ return outbuf
|
|
|
+ }
|
|
|
+
|
|
|
+ for (n = 0; n < (inlen + SM2_ADDBYTE); n++) {
|
|
|
+ outbuf[n] = array_out[2 + n]
|
|
|
+ }
|
|
|
+
|
|
|
+ return outbuf
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_SM2_Dec (inbuf, inlen, pin, KeyPath) {
|
|
|
+ var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
|
|
|
+ var outbuf = new Uint8Array(inlen - SM2_ADDBYTE)
|
|
|
+ var n = 0
|
|
|
+
|
|
|
+ var b_pin = Buffer.from(pin)
|
|
|
+ for (n = 0; n < PIN_LEN; n++) {
|
|
|
+ array_in[1 + PIN_LEN * 0 + n] = b_pin[n]
|
|
|
+ }
|
|
|
+ array_in[1 + PIN_LEN] = inlen
|
|
|
+ for (n = 0; n < inlen; n++) {
|
|
|
+ array_in[1 + PIN_LEN + 1 + n] = inbuf[n]
|
|
|
+ }
|
|
|
+ var array_out = this.SendWithDataNoErr(MYDEC, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) {
|
|
|
+ return outbuf
|
|
|
+ }
|
|
|
+ if (array_out[2] != 0x20) {
|
|
|
+ this.lasterror = FAILPINPWD; return outbuf
|
|
|
+ }
|
|
|
+ if (array_out[1] == 0) {
|
|
|
+ this.lasterror = FAILENC; return outbuf
|
|
|
+ }
|
|
|
+ if (array_out[0] != 0x20) {
|
|
|
+ this.lasterror = USBStatusFail; return outbuf
|
|
|
+ }
|
|
|
+ for (n = 0; n < (inlen - SM2_ADDBYTE); n++) {
|
|
|
+ outbuf[n] = array_out[3 + n]
|
|
|
+ }
|
|
|
+
|
|
|
+ return outbuf
|
|
|
+ }
|
|
|
+
|
|
|
+ sub_NT_Sign (cmd, inbuf, pin, KeyPath) {
|
|
|
+ var outbuf = new Uint8Array(ECC_MAXLEN * 2)
|
|
|
+ var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
|
|
|
+ var n = 0
|
|
|
+
|
|
|
+ var b_pin = Buffer.from(pin)
|
|
|
+ for (n = 0; n < PIN_LEN; n++) {
|
|
|
+ array_in[1 + PIN_LEN * 0 + n] = b_pin[n]
|
|
|
+ }
|
|
|
+ for (n = 0; n < 32; n++) {
|
|
|
+ array_in[1 + PIN_LEN + n] = inbuf[n]
|
|
|
+ }
|
|
|
+ var array_out = this.SendWithDataNoErr(cmd, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) {
|
|
|
+ return outbuf
|
|
|
+ }
|
|
|
+ if (array_out[1] != 0x20) {
|
|
|
+ this.lasterror = FAILPINPWD
|
|
|
+ return outbuf
|
|
|
+ }
|
|
|
+ if (array_out[0] != 0x20) {
|
|
|
+ this.lasterror = USBStatusFail
|
|
|
+ return outbuf
|
|
|
+ }
|
|
|
+ for (n = 0; n < ECC_MAXLEN * 2; n++) {
|
|
|
+ outbuf[n] = array_out[2 + n]
|
|
|
+ }
|
|
|
+
|
|
|
+ return outbuf
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_Sign (inbuf, pin, KeyPath) {
|
|
|
+ return this.sub_NT_Sign(0x51, inbuf, pin, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_Sign_2 (inbuf, pin, KeyPath) {
|
|
|
+ return this.sub_NT_Sign(0x53, inbuf, pin, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ NT_Verfiy (inbuf, InSignBuf, KeyPath) {
|
|
|
+ var array_in = new Uint8Array(SM2_MAX_TRANSE_LEN)
|
|
|
+ var n = 0
|
|
|
+
|
|
|
+ for (n = 0; n < ECC_MAXLEN; n++) {
|
|
|
+ array_in[1 + n] = inbuf[n]
|
|
|
+ }
|
|
|
+ for (n = 0; n < ECC_MAXLEN * 2; n++) {
|
|
|
+ array_in[1 + ECC_MAXLEN + n] = InSignBuf[n]
|
|
|
+ }
|
|
|
+ var array_out = this.SendWithDataNoErr(YTVERIFY, array_in, KeyPath)
|
|
|
+ if (this.lasterror != 0) return false
|
|
|
+ var outbiao = (array_out[1] != 0)
|
|
|
+ if (array_out[0] != 0x20) {
|
|
|
+ this.lasterror = USBStatusFail; return false
|
|
|
+ }
|
|
|
+
|
|
|
+ return outbiao
|
|
|
+ }
|
|
|
+
|
|
|
+ YT_GenKeyPair (KeyPath) {
|
|
|
+ var n
|
|
|
+ var KeyPairInfo = {
|
|
|
+ PriKey: '',
|
|
|
+ PubKeyX: '',
|
|
|
+ PubKeyY: ''
|
|
|
+ }
|
|
|
+ var KEYPAIR = this.NT_GenKeyPair(KeyPath)
|
|
|
+ if (this.lasterror) return KeyPairInfo
|
|
|
+ KeyPairInfo.PriKey = this.ByteArrayToHexString(KEYPAIR.PriKey, ECC_MAXLEN)
|
|
|
+ KeyPairInfo.PubKeyX = this.ByteArrayToHexString(KEYPAIR.PubKeyX, ECC_MAXLEN)
|
|
|
+ KeyPairInfo.PubKeyY = this.ByteArrayToHexString(KEYPAIR.PubKeyY, ECC_MAXLEN)
|
|
|
+
|
|
|
+ return KeyPairInfo
|
|
|
+ }
|
|
|
+
|
|
|
+ Set_SM2_KeyPair (PriKey, PubKeyX, PubKeyY, SM2_UserName, KeyPath) {
|
|
|
+ var b_PriKey = this.HexStringToByteArray(PriKey)
|
|
|
+ var b_PubKeyX = this.HexStringToByteArray(PubKeyX)
|
|
|
+ var b_PubKeyY = this.HexStringToByteArray(PubKeyY)
|
|
|
+
|
|
|
+ var b_SM2UserName = Buffer.from(SM2_UserName)
|
|
|
+
|
|
|
+ return this.NT_Set_SM2_KeyPair(b_PriKey, b_PubKeyX, b_PubKeyY, b_SM2UserName, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ Get_SM2_PubKey (KeyPath) {
|
|
|
+ var PubKeyInfo = {
|
|
|
+ PubKeyX: '',
|
|
|
+ PubKeyY: '',
|
|
|
+ sm2UserName: ''
|
|
|
+ }
|
|
|
+
|
|
|
+ var SM2_PubKeyInfo = this.NT_Get_SM2_PubKey(KeyPath)
|
|
|
+
|
|
|
+ PubKeyInfo.PubKeyX = this.ByteArrayToHexString(SM2_PubKeyInfo.KGx, ECC_MAXLEN)
|
|
|
+ PubKeyInfo.PubKeyY = this.ByteArrayToHexString(SM2_PubKeyInfo.KGy, ECC_MAXLEN)
|
|
|
+ PubKeyInfo.sm2UserName = new Buffer(SM2_PubKeyInfo.sm2_UerName).toString()
|
|
|
+ return PubKeyInfo
|
|
|
+ }
|
|
|
+
|
|
|
+ SM2_EncBuf (InBuf, inlen, KeyPath) {
|
|
|
+ var n, temp_inlen, incount = 0, outcount = 0
|
|
|
+ var temp_InBuf = new Uint8Array(MAX_ENCLEN + SM2_ADDBYTE)
|
|
|
+ var OutBuf = Buffer.alloc(0)
|
|
|
+ // InBuf.copy(OutBuf);
|
|
|
+ while (inlen > 0) {
|
|
|
+ if (inlen > MAX_ENCLEN) { temp_inlen = MAX_ENCLEN } else { temp_inlen = inlen }
|
|
|
+ for (n = 0; n < temp_inlen; n++) {
|
|
|
+ temp_InBuf[n] = InBuf[incount + n]
|
|
|
+ }
|
|
|
+ var temp_OutBuf = this.NT_SM2_Enc(temp_InBuf, temp_inlen, KeyPath)
|
|
|
+ if (this.lasterror) return OutBuf
|
|
|
+ OutBuf = Buffer.concat([OutBuf, temp_OutBuf])
|
|
|
+ inlen = inlen - MAX_ENCLEN
|
|
|
+ incount = incount + MAX_ENCLEN
|
|
|
+ outcount = outcount + MAX_DECLEN
|
|
|
+ }
|
|
|
+
|
|
|
+ return OutBuf
|
|
|
+ }
|
|
|
+
|
|
|
+ SM2_DecBuf (InBuf, inlen, pin, KeyPath) {
|
|
|
+ var temp_inlen, n, incount = 0, outcount = 0
|
|
|
+ var temp_InBuf = new Uint8Array(MAX_ENCLEN + SM2_ADDBYTE)
|
|
|
+ var OutBuf = Buffer.alloc(InBuf.length)
|
|
|
+ // var b=new Buffer(InBuf)
|
|
|
+ // b.copy(OutBuf);
|
|
|
+ var OutBuf = Buffer.alloc(0)
|
|
|
+ while (inlen > 0) {
|
|
|
+ if (inlen > MAX_DECLEN) { temp_inlen = MAX_DECLEN } else { temp_inlen = inlen }
|
|
|
+ for (n = 0; n < temp_inlen; n++) {
|
|
|
+ temp_InBuf[n] = InBuf[incount + n]
|
|
|
+ }
|
|
|
+ var temp_OutBuf = this.NT_SM2_Dec(InBuf, temp_inlen, pin, KeyPath)
|
|
|
+ if (this.lasterror) return OutBuf
|
|
|
+ OutBuf = Buffer.concat([OutBuf, temp_OutBuf])
|
|
|
+ inlen = inlen - MAX_DECLEN
|
|
|
+ incount = incount + MAX_DECLEN
|
|
|
+ outcount = outcount + MAX_ENCLEN
|
|
|
+ }
|
|
|
+ return OutBuf
|
|
|
+ }
|
|
|
+
|
|
|
+ SM2_EncString (InString, KeyPath) {
|
|
|
+ var InBuf = Buffer.from(InString)
|
|
|
+ var OutBuf = this.SM2_EncBuf(InBuf, InBuf.length, KeyPath)
|
|
|
+ if (this.lasterror) return OutBuf
|
|
|
+ return this.ByteArrayToHexString(OutBuf, OutBuf.length)
|
|
|
+ }
|
|
|
+
|
|
|
+ SM2_DecString (InString, pin, KeyPath) {
|
|
|
+ var InBuf = this.HexStringToByteArray(InString)
|
|
|
+
|
|
|
+ var OutBuf = this.SM2_DecBuf(InBuf, InBuf.length, pin, KeyPath)
|
|
|
+
|
|
|
+ return OutBuf.toString()
|
|
|
+ }
|
|
|
+
|
|
|
+ YtSetPin (old_pin, new_pin, KeyPath) {
|
|
|
+ return this.NT_Set_Pin(old_pin, new_pin, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ Sub_YtSign (cmd, msg, pin, KeyPath) {
|
|
|
+ var OutSign
|
|
|
+
|
|
|
+ var MsgHashValue = sm3(msg)
|
|
|
+ var Inbuf = new Buffer.from(MsgHashValue, 'hex')
|
|
|
+ var OutBuf = this.sub_NT_Sign(cmd, Inbuf, pin, KeyPath)
|
|
|
+ if (this.lasterror != 0) return OutSign
|
|
|
+ OutSign = new Buffer(OutBuf).toString('hex')
|
|
|
+ return OutSign
|
|
|
+ }
|
|
|
+
|
|
|
+ YtSign (msg, pin, KeyPath) {
|
|
|
+ return this.Sub_YtSign(0x51, msg, pin, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ YtSign_2 (msg, pin, KeyPath) {
|
|
|
+ return this.Sub_YtSign(0x53, msg, pin, KeyPath)
|
|
|
+ }
|
|
|
+
|
|
|
+ CheckKeyByFindort_2 () {
|
|
|
+ // ??????????????????????
|
|
|
+ var DevicePath = '' // ??????????????��??
|
|
|
+ DevicePath = this.FindPort_2(0, 1, -909931691)
|
|
|
+ return this.lasterror
|
|
|
+ }
|
|
|
+
|
|
|
+ // ??????????????????????��???????
|
|
|
+ ReadStringEx (addr, DevicePath) {
|
|
|
+ var nlen
|
|
|
+ // ?????0??????��????????????
|
|
|
+ var OutData = this.YReadEx(addr, 1, '6398277A', '8388014E', DevicePath)
|
|
|
+ if (this.lasterror != 0) return ''
|
|
|
+ nlen = OutData[0]
|
|
|
+ // ?????????????????
|
|
|
+ return this.YReadString(addr + 1, nlen, '6398277A', '8388014E', DevicePath)
|
|
|
+ }
|
|
|
+ // ??????????????????????????????????????????
|
|
|
+ CheckKeyByReadEprom () {
|
|
|
+ var n, ret
|
|
|
+
|
|
|
+ // @NoUseCode_data return 1;//???????????????????????1
|
|
|
+ for (n = 0; n < 255; n++) {
|
|
|
+ var DevicePath = this.FindPort(n)// ??????????????��??
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ var outString = this.ReadStringEx(0, DevicePath)
|
|
|
+ if ((this.lasterror == 0) && (outString == 'FM1XhyDQ5z0DIISIhvu6uwTP8uBUxtnK')) return 0
|
|
|
+ }
|
|
|
+ return -92
|
|
|
+ }
|
|
|
+ // ????????????????????????????????��????????
|
|
|
+ CheckKeyByEncstring () {
|
|
|
+ // ???????????????????????????????????????????????????????????????????????��??
|
|
|
+
|
|
|
+ var n, ret
|
|
|
+
|
|
|
+ var InString
|
|
|
+
|
|
|
+ // @NoUseKeyEx return 1;//???????????????????????1
|
|
|
+ var number1 = Math.floor(Math.random() * 65535)
|
|
|
+ var number2 = Math.floor(Math.random() * 65535)
|
|
|
+
|
|
|
+ InString = number1.toString() + number2.toString()
|
|
|
+
|
|
|
+ for (n = 0; n < 255; n++) {
|
|
|
+ var DevicePath = this.FindPort(n)// ??????????????��??
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ if (this.Sub_CheckKeyByEncString(InString, DevicePath) == 0) return 0
|
|
|
+ }
|
|
|
+ return -92
|
|
|
+ }
|
|
|
+
|
|
|
+ Sub_CheckKeyByEncString (InString, DevicePath) {
|
|
|
+ // ???????????????????��???
|
|
|
+
|
|
|
+ var outString = this.EncString(InString, DevicePath)
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+ var outString_2 = this.StrEnc(InString, '4326BBDEB43352C31FED71B466A0E879')
|
|
|
+ if (outString_2.toUpperCase() == outString.toUpperCase())// ???????????
|
|
|
+ {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ return -92
|
|
|
+ }
|
|
|
+
|
|
|
+ // ??????????????????????????????????��??????????
|
|
|
+ CheckKeyByEncstring_New () {
|
|
|
+ var n, ret
|
|
|
+ var myrnd = Math.floor(Math.random() * 500)
|
|
|
+ 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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '21220', '16565', '25169', '29778', '12747', '5865', '9980', '28792', '32481', '2829', '22617', '21259', '4915', '14850', '10177', '28668', '15079', '26443', '21165', '30429' ]
|
|
|
+ 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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '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',
|
|
|
+ '5FCA2A8523983788', '09AD2AD3630656D9', 'BFAF8BE5DFDC6C53', '06BE62AEBB8EC40E', 'B0E68E7A21762CEE', '6CC82CFBBDDD7AB6', '30CC28851C745E19', '901A7611BB5D9F44', 'D76E0E705F830FFA', '0F13602C99462F16', '43B72D9F1963D646', '9FB0769CCB26AE45', '9B12999075597D2F', 'C62395CF5A3FFAEF', '6C9C943CC52D8325', 'F5B48F8384BCA968', '4314CCE0E9F230E6', '0368A40BDA81480A', '3DEC51FD2C223A7E', '71989114D1B74DC7' ]
|
|
|
+ // @NoUseNewKeyEx return 1;//???????????????????????1
|
|
|
+ // @NoSupNewKeyEx return 2;//???????????????????????2
|
|
|
+
|
|
|
+ var mEncInString = EncInString[myrnd]
|
|
|
+ var mEncOutString = EncOutString[myrnd]
|
|
|
+ for (n = 0; n < 255; n++) {
|
|
|
+ var DevicePath = this.FindPort(n)// ??????????????��??
|
|
|
+ if (this.lasterror != 0) return this.lasterror
|
|
|
+
|
|
|
+ var outString = this.EncString_New(mEncInString, DevicePath)
|
|
|
+ if ((this.lasterror == 0) && (outString.toUpperCase() == mEncOutString.toUpperCase())) return 0
|
|
|
+ }
|
|
|
+ return -92
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// vid,pid
|
|
|
+mSoftKey.VID = 0x3689
|
|
|
+mSoftKey.PID = 0x8762
|
|
|
+mSoftKey.PID_NEW = 0X2020
|
|
|
+mSoftKey.VID_NEW = 0X3689
|
|
|
+mSoftKey.PID_NEW_2 = 0X2020
|
|
|
+mSoftKey.VID_NEW_2 = 0X2020
|
|
|
+
|
|
|
+export default mSoftKey
|