I cant change key

  • 30. April 2015 at 8:08
    please help me .
    I'm using DES.
    see my result in text file
    + 0  |  - 0

    Re: I cant change key

    13. May 2015 at 16:24
    Hi,

    from the log I see that the authenticate was successful. Then you select application ID 000000. Then the log show data bytes sent to the PICC. It seems that you do not use the ChangeKey command properly.

    Best regards,
    The MIFARE Team
    + 0  |  - 0

    Re: I cant change key

    11. January 2016 at 21:47
    I have a problem. Please help me
    I select app 000000 with no error.
    I use DES and auth... with no error.
    I have problem with making 24 byte data for change master key.
    I dont use mifaresdk.
    My old key is 00 00 00 00 00 00 00 00
    8 byte for des .
    How to create 24 byte data. I read datasheet but i dont undrestand .
    Use crc , how can i make crc . I need c code. Please tell me completly.
    + 0  |  - 0

    Re: I cant change key

    12. January 2016 at 9:38
    bool MifareDesfire_ChangeMasterKey(uint8_t *OldKey,uint8_t *NewKey)
    {
    uint8_t NewKeyBuffer[24];
    uint8_t SessionKey[8];
    uint16_t crc;
    MifareDesFire_Authenicate(0,DesfireAppID000,OldKey,SessionKey);

    pn532_packetbuffer[0] = PN532_COMMAND_INDATAEXCHANGE;
    pn532_packetbuffer[1] = 1; // max 1 cards at once (we can set this to 2 later)
    pn532_packetbuffer[2] = MIFARE_DESFIRE_CMD_CHANGEKEY;
    pn532_packetbuffer[3] = 0;

    for(uint8_t i=0; i<8 ; i++)
    NewKeyBuffer = OldKey ^ NewKey;
    for(uint8_t i=8; i> 8;

    crc = GetCrc(NewKey,8,0xCC69,0xffff);

    NewKeyBuffer[18] = crc&0x00ff;
    NewKeyBuffer[19] = (crc&0xff00) >> 8;

    for(uint8_t i=20; i<24 ; i++)
    NewKeyBuffer = 0;

    desInit(&myDes,OldKey,8);
    desDecryptBlock(&myDes,&NewKeyBuffer[0],&NewKeyBuffer[0]);
    desDecryptBlock(&myDes,&NewKeyBuffer[8],&NewKeyBuffer[8]);
    desDecryptBlock(&myDes,&NewKeyBuffer[16],&NewKeyBuffer[16]);

    for(uint8_t i=0; i<24; i++)
    pn532_packetbuffer = NewKeyBuffer;
    if (!PN532_sendCommandCheckAck(pn532_packetbuffer, 28, 500))
    {
    #ifdef MIFARE_DEBUGMODE
    printf("PICC Can Not Change Pin\n\r");
    #endif
    return false;

    }

    if (!PN532_waitready(500))
    {
    #ifdef MIFARE_DEBUGMODE
    printf("PICC Can Not Change Pin\n\r");
    #endif
    return false;
    }
    PN532_readdata(pn532_packetbuffer, 0);
    if(pn532_packetbuffer[7] != 0)
    {
    #ifdef MIFARE_DEBUGMODE
    printf("PICC Can Not Change Pin\n\r");
    #endif
    return false;
    }
    if(pn532_packetbuffer[8] != 0)
    {
    #ifdef MIFARE_DEBUGMODE
    printf("PICC Can Not Change Pin\n\r");
    #endif
    return false;
    }


    #ifdef MIFARE_DEBUGMODE
    printf("PICC Pin Changed\n\r");
    #endif

    return true;
    }
    + 0  |  - 0

    Re: I cant change key

    12. January 2016 at 9:39
    // this function calculates a CRC16 over a unsigned char Array with, LSB first
    // @Param1 (DataBuf): An Array, which contains the Data for Calculation
    // @Param2 (SizeOfDataBuf): length of the Data Buffer (DataBuf)
    // @Param3 (Polynom): Value of the Generatorpolynom, 0x8408 is recommended
    // @Param4 (Initial_Value): load value for CRC16, 0xFFFF is recommended for
    // host to reader communication
    // return: calculated CRC16
    uint16_t GetCrc( uint8_t *DataBuf,uint8_t SizeOfDataBuf,uint16_t Polynom,uint16_t Initial_Value)
    {

    uint16_t Crc16;
    uint8_t Byte_Counter, Bit_Counter;
    Crc16 = Initial_Value;
    for (Byte_Counter=0; Byte_Counter < SizeOfDataBuf; Byte_Counter++)
    {
    Crc16^=DataBuf[Byte_Counter];
    for (Bit_Counter=0; Bit_Counter>=1;
    else
    Crc16=(Crc16>>1)^Polynom;
    }
    }
    return (Crc16);
    }
    + 0  |  - 0
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.