如何使用C#在MIFARE classic 1k的2个块中存储20个字节的任何数据 [英] How to store any data of 20 bytes in 2 blocks of MIFARE classic 1k using C#

查看:106
本文介绍了如何使用C#在MIFARE classic 1k的2个块中存储20个字节的任何数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

请告诉我,我正在使用MIFARE经典1k卡,我有一个字段NAME,长度为20个字节,因为1个块在mifare = 16个字节o用于休息我可以在第二个块中恢复4个字节。



我尝试了什么:



i现在只尝试了16个字节。



Hi all,
Please let me know that i am using MIFARE classic 1k card, i have a field "NAME" which is 20 bytes long since 1 block in mifare=16 bytes o for rest 4 bytes how i can restore in second block.

What I have tried:

i have tried now with 16 bytes only.

string tmpStr;
            int indx;

            string BlockNumber_Name = "36";
            string BlockNumber_Id = "37";
            string BlockNumber_Date = "38";
            string DataLength = "16";



            int tempInt;
            if (BlockNumber_Name == "" | !int.TryParse(BlockNumber_Name, out tempInt))
            {

                //  tBinBlk.Focus();
                BlockNumber_Name = "";
                return;
            }
            if (int.Parse(BlockNumber_Name) > 319)
            {

                BlockNumber_Name = "319";
                return;

            }

            if (DataLength == "" | !int.TryParse(DataLength, out tempInt))
            {

                // tBinLen.Focus();
                DataLength = "";
                return;

            }


            if (Name_txt.Text == "")
            {

                Name_txt.Focus();
                return;

            }


            tmpStr = Name_txt.Text;

            ClearBuffers();
            SendBuff[0] = 0xFF;                                     // CLA
            SendBuff[1] = 0xD6;                                     // INS
            SendBuff[2] = 0x00;                                     // P1
            SendBuff[3] = (byte)int.Parse(BlockNumber_Name);            // P2 : Starting Block No.
            SendBuff[4] = (byte)int.Parse(DataLength);            // P3 : Data length

            for (indx = 0; indx <= (tmpStr).Length - 1; indx++)
            {

                SendBuff[indx + 5] = (byte)tmpStr[indx];

            }
            SendLen = SendBuff[4] + 5;
            RecvLen = 0x02;

推荐答案

因为页面的大小为16字节,所以必须发送两个写命令:

一个已经完成,另一个有块号+ 1,数据从 tempStr 的偏移量16开始,长度为4。



但是这会与你的例子中的 Id 块号冲突。因此,如果该区号是正确的,或者 Id 可能存储在该区块的偏移4处,您应该检查卡的文档。



顺便说一句:为什么你使用字符串作为只是字节的参数?

如果它们来自输入字段,我会先检查并转换它们。然后你可以实现一个接受数字参数而不是字符串的写函数。
Because a page has a size of 16 bytes, you have to send two write commands:
One as already done and another one with the block number + 1, the data starting at offset 16 of your tempStr, and the length 4.

But this would conflict with the Id block number from your example. So you should check the documentation for your card if that block number is correct or if the Id might be stored at offset 4 in that block.

BTW: Why do you use strings for the parameters which are just bytes?
If they are from input fields I would check and convert them first. Then you can implement a write function accepting numeric parameters instead of strings.


我写了这个





i have write this


string blkAuth = "36";
            string blk1 = "36";
            string blk2 = "37";
            string blk3 = "38";

            string val1 = Passid_txt.Text; //username
            string fullname = Name_txt.Text;
            string val2 = fullname.Substring(0, 14);  //validity 
            string val3 = fullname.Substring(14,6);

            write_authenticaion(blkAuth,blk1,blk2,blk3,val1,val2,val3);
            

             string blkAuth11 = "40";
            string blk11 = "40";
            string blk21 = "41";
            string blk31 = "42";

            string val11 = validdate_txt.Text;//username
            string val21 = prmsble_txt.Text;//validity
            string val31 = upjrnydate_txt.Text;

            write_authenticaion(blkAuth11,blk11,blk21,blk31,val11,val21,val31);







where_authentication是我声明认证APDUs的类




where_authentication is class where i declare authentication APDUs


这篇关于如何使用C#在MIFARE classic 1k的2个块中存储20个字节的任何数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆