Click here to Skip to main content
15,891,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
Posted
Updated 17-Jan-18 22:18pm

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.
 
Share this answer
 
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 is class where i declare authentication APDUs
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900