/// <summary> /// 验证密码 /// </summary> /// <param name="nSector"></param> /// <param name="strKey"></param> /// <returns></returns> private int AuthKey(int nSector, string strKey) { int nReturn = -1; byte[] szKey1 = new byte[17]; byte[] szKey2 = new byte[7]; int i = 0; int nKeyLen = strKey.Length; if (nKeyLen != 12) { return(-1); } if (nSector < 1 || nSector > 15) { return(-1); } for (i = 0; i < nKeyLen; i++) { if (strKey[i] >= '0' && strKey[i] <= '9') { continue; } if (strKey[i] <= 'a' && strKey[i] <= 'f') { continue; } if (strKey[i] <= 'A' && strKey[i] <= 'F') { continue; } } if (i != nKeyLen) { return(-1); } szKey1 = Encoding.ASCII.GetBytes(strKey); if (m_bIs64BitOperatingSystem) { //64位系统 if (USB_SWIPER == m_nComID) { CQTCommonForUsb.a_hex(szKey1, szKey2, 12); nReturn = CQTCommonForUsb.rf_load_key(m_nEquipDesc, m_nAuthKeyMode, nSector, szKey2); if (nReturn != 0) { return(nSector); } nReturn = CQTCommonForUsb.rf_authentication(m_nEquipDesc, m_nAuthKeyMode, nSector); } else { CQTCommon.a_hex(szKey1, szKey2, 12); nReturn = CQTCommon.rf_load_key(m_nEquipDesc, m_nAuthKeyMode, nSector, szKey2); if (nReturn != 0) { return(nSector); } nReturn = CQTCommon.rf_authentication(m_nEquipDesc, m_nAuthKeyMode, nSector); } } else { //其他位系统 if (USB_SWIPER == m_nComID) { CQTCommonForUsb.a_hex(szKey1, szKey2, 12); nReturn = CQTCommonForUsb.rf_load_key(m_nEquipDesc, m_nAuthKeyMode, nSector, szKey2); if (nReturn != 0) { return(nSector); } nReturn = CQTCommonForUsb.rf_authentication(m_nEquipDesc, m_nAuthKeyMode, nSector); } else { CQTCommon.a_hex(szKey1, szKey2, 12); nReturn = CQTCommon.rf_load_key(m_nEquipDesc, m_nAuthKeyMode, nSector, szKey2); if (nReturn != 0) { return(nSector); } nReturn = CQTCommon.rf_authentication(m_nEquipDesc, m_nAuthKeyMode, nSector); } } return(nReturn); }
/// <summary> /// 向感应区内所选定卡的指定扇区(0~15)的指定数据块(0~3)写入数据(16字节或者6字节(密码)十六进制)。函数返回值,-1表示验证密码失败,0表示操作成功,其他表示读失败 /// </summary> /// <param name="nSector">指定扇区</param> /// <param name="nDBNum">指定扇区中的指定DB块</param> /// <param name="strWrite">写入的数据(16字节或6字节),十六进制数</param> /// <returns>函数返回值,-1表示验证密码失败,0表示操作成功,其他表示读失败</returns> public override int WriteDataIntoCard(Int16 nSector, Int16 nDBNum, string strWrite) { strWrite += "FF"; byte[] bBuff = new byte[32]; byte[] bWrite = new byte[16]; int nCounter = 0; for (nCounter = 0; nCounter < strWrite.Length; nCounter++) { if (strWrite[nCounter] >= '0' && strWrite[nCounter] <= '9') { continue; } if (strWrite[nCounter] <= 'a' && strWrite[nCounter] <= 'f') { continue; } if (strWrite[nCounter] <= 'A' && strWrite[nCounter] <= 'F') { continue; } } if (nCounter != strWrite.Length) { // lbResult.Text = "data is hex data!"; return(1); } bBuff = Encoding.ASCII.GetBytes(strWrite); if (m_bIs64BitOperatingSystem) { //64位系统 if (USB_SWIPER == m_nComID) { CQTCommonForUsb.a_hex(bBuff, bWrite, 32); } else { CQTCommon.a_hex(bBuff, bWrite, 32); } } else { //其他位系统 if (USB_SWIPER == m_nComID) { CQTCommonForUsb.a_hex(bBuff, bWrite, 32); } else { CQTCommon.a_hex(bBuff, bWrite, 32); } } int nBack = 1; int blocknum = nSector * 4 + nDBNum; if (m_bIs64BitOperatingSystem) { //64位系统 if (USB_SWIPER == m_nComID) { nBack = CQTCommonForUsb.rf_authentication(m_nEquipDesc, m_nAuthKeyMode, nSector); } else { nBack = CQTCommon.rf_authentication(m_nEquipDesc, m_nAuthKeyMode, nSector); } } else { //其他位系统 if (USB_SWIPER == m_nComID) { nBack = CQTCommonForUsb.rf_authentication(m_nEquipDesc, m_nAuthKeyMode, nSector); } else { nBack = CQTCommon.rf_authentication(m_nEquipDesc, m_nAuthKeyMode, nSector); } } if (nBack != 0) { return(-1); } if (m_bIs64BitOperatingSystem) { //64位系统 if (USB_SWIPER == m_nComID) { nBack = CQTCommonForUsb.rf_write(m_nEquipDesc, (short)blocknum, bWrite); CQTCommonForUsb.rf_beep(m_nEquipDesc, 50); } else { nBack = CQTCommon.rf_write(m_nEquipDesc, (short)blocknum, bWrite); CQTCommon.rf_beep(m_nEquipDesc, 50); } } else { //其他位系统 if (USB_SWIPER == m_nComID) { nBack = CQTCommonForUsb.rf_write(m_nEquipDesc, (short)blocknum, bWrite); CQTCommonForUsb.rf_beep(m_nEquipDesc, 50); } else { nBack = CQTCommon.rf_write(m_nEquipDesc, (short)blocknum, bWrite); CQTCommon.rf_beep(m_nEquipDesc, 50); } } return(nBack); }