Schlagwort-Archive: MFRC522

RFID / Arduino : Copy a card with known keys,


Today I want to show you how to copy a Mifare classic card with the arduino mega and the rfid-rc522 module.


  • Card Reader
  • Arduino Mega
  • Arduino Library
  • Existing RFID Card ( in this example a Mifare Classic 1k )
  • New empty RFID Card

Card Reader

Recently I bought a RFID-RC522 Module from aliexpress( ~ 5$ ) .

RFID Module Board RC522
RFID Module Board RC522
Connect the board with the Arduino Mega.
 * Pin layout should be as follows:
 * Signal Pin Pin Pin
 * Arduino Mega MFRC522 board
 * ------------------------------------------------------------
 * Reset      5    RST
 * SPI SS    53    SDA
 * SPI MOSI  51    MOSI
 * SPI MISO  50    MISO
 * SPI SCK   52    SCK
 * #Note: Code will work not with Arduino UNO because of not enough SRAM

Arduino Mega

I used an Arduino  MEGA 2560, because UNO had to lees RAM. Note: We have to read a 1K card and keep this in memory.

Arduino Library

For accessing there exists a lot of arduino libraries in the net. I do not know which library I used exactly, think it was from here.

Existing RFID Card

mifare_classic_1K In my example I used an existing Mifare Classic 1K card. This piece of code gives you info about your card. Serial.print(" PICC type: "); // Dump PICC type byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak); Serial.println(mfrc522.PICC_GetTypeName(piccType));

New empty RFID Card

Any new card. Please note that the UID number of an existing card couldn’t be copied. The UID number of an new card is normally read only, and programmed by the manufactory of the cards. Except, so called >> Chinese magic rfid card<<. My code example do not try to write the read UID number to the new card.


In general I am a little bit lazy to give you a big explanation about the code. Just download it and go through… But okay some info’s I want to give you: Please note: serial baud rate is 57600 Please do not forget to change your keys

 byte KeyA_List[][6] =
 {150,161,162,166,164,165}, // Sector 0
 byte KeyB_List[][6] =
 {134,135,136,137,138,139}, // Sector 0

Basic flow: Idea is to read a card , dump this information


and also add the KEY A and KEY B infos to the dumped data. see comments in my code

// Special note on KEY_A / KEY_B
// see datasheet
// When the sector trailer is read, the key bytes are blanked out by returning logical zeros. If
// Key B is configured to be readable, the data stored in bytes 10 to 15 is returned, see

So this is my first version.