Пример #1
0
        /// <summary>
        /// 证实指定扇区
        /// </summary>
        /// <param name="sectorNum">要证实的扇区</param>
        /// <returns>证实成功则返回 true,否则返回 fasle。</returns>
        private async Task <bool> AuthKey(byte sectorNum)
        {
            byte[] keyA = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
            //密码 A 证实
            var info3 = await i14443a.AuthKeyAsync(KeyType.KeyA, sectorNum, keyA);

            if (info3.ReturnValue != ReturnMessage.Success)
            {
                Console.WriteLine(info3.GetStatusStr());
                return(false);
            }
            return(true);
        }
Пример #2
0
        //选卡
        private static async Task <bool> AuthKey(byte sectorNum)
        {
            await reader.ChangeToISO14443AAsync();

            //请求操作
            var info = await i14443a.RequestAsync(RequestMode.AllCard);

            if (info.ReturnValue != ReturnMessage.Success)
            {
                Console.WriteLine(info.GetStatusStr());
                return(false);
            }
            //防冲突操作
            var info1 = await i14443a.AnticollAsync();

            if (info1.ReturnValue != ReturnMessage.Success)
            {
                Console.WriteLine(info1.GetStatusStr());
                return(false);
            }
            //选卡操作
            var info2 = await i14443a.SelectAsync(info1.UID);

            if (info2.ReturnValue == ReturnMessage.Success)
            {
                Console.WriteLine("选中标签:" + info1.GetUIDStr());
            }
            else
            {
                Console.WriteLine(info2.GetStatusStr());
                return(false);
            }

            //证实
            byte[] keyA = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
            //密码 A 证实
            var info3 = await i14443a.AuthKeyAsync(KeyType.KeyA, sectorNum, keyA);

            if (info3.ReturnValue != ReturnMessage.Success)
            {
                Console.WriteLine(info3.GetStatusStr());
                return(false);
            }
            Console.WriteLine("证实成功");
            return(true);
        }
Пример #3
0
        private async Task ChangePsw(KeyType keyType)
        {
            if (txtSelCard.Text == "")
            {
                MessageBox.Show("请先进行选卡操作!", "提示信息", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (txtOldKey.Text == "" || txtNewKey.Text == "")
            {
                MessageBox.Show("请在密码A编辑框和新密码编辑框输入相应密码!", "提示信息", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            byte[] keyA;
            if (txtOldKey.Text == "默认")
            {
                keyA = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
            }
            else
            {
                keyA = new byte[6];
                byte[] b = Encoding.ASCII.GetBytes(txtOldKey.Text);
                if (b.Length > 6)
                {
                    MessageBox.Show("密码A编辑框输入的密码超出长度!", "错误信息", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                b.CopyTo(keyA, 0);
            }

            var info = await i14443a.AuthKeyAsync(KeyType.KeyA, 15, keyA);

            this.Dispatcher.Invoke(new Action(() =>
            {
                txtMsg.Text = "发送的字节:" + info.GetSendByteStr();
                txtMsg.AppendText("\r\n接收的字节:" + info.GetRecvByteStr());
                txtMsg.AppendText("\r\n" + info.GetStatusStr());
            }));
            if (info.ReturnValue != ReturnMessage.Success)
            {
                return;
            }

            var info1 = await i14443a.ReadAsync(63);

            this.Dispatcher.Invoke(new Action(() =>
            {
                txtMsg.AppendText("\r\n\r\n发送的字节:" + info1.GetSendByteStr());
                txtMsg.AppendText("\r\n接收的字节:" + info1.GetRecvByteStr());
                txtMsg.AppendText("\r\n读取结果:" + info1.GetBlockDataStr());
                txtMsg.AppendText("\r\n" + info1.GetStatusStr());
            }));
            if (info1.ReturnValue != ReturnMessage.Success)
            {
                return;
            }

            byte[] newKey = new byte[6];
            byte[] b1     = Encoding.ASCII.GetBytes(txtNewKey.Text);
            if (b1.Length > 6)
            {
                MessageBox.Show("新密码超出长度!", "错误信息", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            b1.CopyTo(newKey, 0);

            byte[] newData = info1.BlockData;
            if (keyType == KeyType.KeyA)
            {
                newKey.CopyTo(newData, 0);
            }
            else
            {
                keyA.CopyTo(newData, 0);
                newKey.CopyTo(newData, 10);
            }

            var info2 = await i14443a.WriteAsync(63, newData);

            this.Dispatcher.Invoke(new Action(() =>
            {
                txtMsg.AppendText("\r\n\r\n发送的字节:" + info2.GetSendByteStr());
                txtMsg.AppendText("\r\n接收的字节:" + info2.GetRecvByteStr());
                txtMsg.AppendText("\r\n" + info2.GetStatusStr());
            }));
            if (info2.ReturnValue == ReturnMessage.Success)
            {
                if (keyType == KeyType.KeyA)
                {
                    txtOldKey.Text = txtNewKey.Text;
                }
            }
        }