Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default factory Key #627

Open
clooner80 opened this issue May 1, 2024 · 0 comments
Open

Change default factory Key #627

clooner80 opened this issue May 1, 2024 · 0 comments

Comments

@clooner80
Copy link

clooner80 commented May 1, 2024

Hi
Im trying to change default key of a rfid tag from this
FFFFFFFFFFFF
To this
111111111111
using Arduino and Mfrc522 module.
The problem is i get this error in serial monitor:
-> Authentication failed: Timeout in communication.
What should i do to be able to change this factory key? Dumpinfo example from the Mfrc522 library works perfectly, so it's not connections or wiring problem.

Here is my code:
`#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

// Define the sector trailer block where the access bits are stored
#define TRAILER_BLOCK 3

void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println(F("Change access bits and authentication key for a MIFARE PICC "));
}

void loop() {
// Prepare the current and new keys
MFRC522::MIFARE_Key currentKey;
MFRC522::MIFARE_Key newKey;
for (byte i = 0; i < 6; i++) {
currentKey.keyByte[i] = 0xFF; // Default key
newKey.keyByte[i] = 0x11; // New key (change this to your desired key)
}

// Reset the loop if no new card present on the sensor/reader
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}

// Select one of the cards
if (!mfrc522.PICC_ReadCardSerial()) {
return;
}

// Authenticate with the current key
byte block = 1; // Example block to authenticate
MFRC522::StatusCode status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &currentKey, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print(F("Authentication failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}

// Change authentication key
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &newKey, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print(F("Key change failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}

// Inform about successful key change
Serial.println(F("Access bits and authentication key changed successfully"));

mfrc522.PICC_HaltA(); // Halt PICC
mfrc522.PCD_StopCrypto1(); // Stop encryption on PCD
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant