Use RFID UID as Authentication Key For sectors and blocks

Hi

I am working on a project using RFID and it is based on Writing Data to Sectors and blocks and later read them which shows the details of card owner which is simple.

For now i am using My own Key for Encrypting it but would like it more secure and

would like to use the the first 6 Bytes of the UID as Authentication Key from sector 0 Which is Encrypted by my own key so please help me on this whenever i try to read the block 0 and get the string they are just random characters

so please help me get this project working as soon as possible

Controller, code and wiring please. My chrystal ball is out of service.

Railroader:
Controller, code and wiring please. My chrystal ball is out of service.

I am using a Uno and a MFRC522 RFID Reader and i wrote this simple code i tried yesterday but i guess i may fail cause i got Authentication failed error

  byte buffer6[18];

  block = 0;
  len = 18;

  //------------------------------------------- GET FIRST NAME
  status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid)); //line 834 of MFRC522.cpp file
  if (status != MFRC522::STATUS_OK) {
        unknown();

    Serial.print(F("Authentication failed: "));
    Serial.println(mfrc522.GetStatusCodeName(status));
    return;
  }

  status = mfrc522.MIFARE_Read(block, buffer6, &len);
  if (status != MFRC522::STATUS_OK) {
    Serial.print(F("Reading failed: "));
    Serial.println(mfrc522.GetStatusCodeName(status));
    return;
  }

String Key = "";
  //PRINT FIRST NAME
  for (byte i = 0; i < 18; i++) 
  {
     Key.concat(String(buffer6[i] < 0x18 ? " 0" : " "));
     Key.concat(String(buffer6[i], HEX));
  }
        Key.remove(18);
        Key.toUpperCase();
        Key.replace(" ", ", 0x");
        Key.remove(0, 2);
   Serial.print("Key: ");
         Serial.print(Key); 

  Serial.println();
  
  if (Key.length() > 0) {
  byte inArray[6];
  char * tokens;
  char key_array[Key.length()];
  Key.toCharArray(key_array, Key.length());
    int i = 0;    
    tokens = strtok(key_array, ", ");
    while (tokens != NULL) {
        inArray[i] = atoi(tokens);
        tokens = strtok(NULL, ", ");
        i++;
    }
    inArray[0] = key.keyByte[0];
    inArray[1] = key.keyByte[1];
    inArray[2] = key.keyByte[2];
    inArray[3] = key.keyByte[3];
    inArray[4] = key.keyByte[4];
    inArray[5] = key.keyByte[5];

  }

That does not look like the entire code.
Where is the mrfc522.begin() ?

Railroader:
That does not look like the entire code.
Where is the mrfc522.begin() ?

I know but after a night less sleep i figured it out and i wanted to keep this project as private as possible as it is for a commerical product and and the code i presented before was which gives out the unique key for each card

So thanks for responding for it

Thank You So much

Okey, You're up and running. Note that all helpers do this without getting paid, without commercial interests, and the intention of Forum is to help new members getting ahead…...