MIFARE Authentication and Key Management Explained

How does MIFARE Classic authentication work? Every sector of a MIFARE Classic card has its own two 6-byte keys, key A and key B, stored in the sector's last block (the sector trailer) together with the access bits. Before the reader can read or write a block, it must authenticate the sector with one of those keys. The access bits decide what each key may then do. New cards leave the factory with both keys set to FF FF FF FF FF FF and the access bytes set to FF 07 80, the "transport configuration". Anyone who knows that public key can read and rewrite the card, which is why production systems must change the keys.

This page explains the concepts behind that: key A and key B, what the access bits control, why default keys must go, key diversification, where keys should be stored, and what NXP itself says about the security of MIFARE Classic, with migration advice to MIFARE DESFire. It contains no code that changes keys or access bits, and nothing about obtaining keys you were not given. For reading cards in code, see how to read MIFARE Classic cards using C#. To test a card with the ACS tools, see the MIFARE card test guide. BSD Infotech is an independent ACS supplier and integrator, not the manufacturer.

A MIFARE Classic 1K card has 16 sectors of 4 blocks (the layout is drawn in our C# reading tutorial). Security works per sector:

  1. The reader holds the key. With an ACS reader, your program first loads the 6-byte key into one of the reader's volatile key locations with the PC/SC Load Keys command (FF 82). The key is not sent to the card.
  2. Reader and card prove to each other that they know the same key. NXP's data sheet calls this a mutual three-pass authentication. Your program triggers it with General Authenticate (FF 86), naming a block, key A or key B, and the key location.
  3. The session is encrypted. After a successful authentication, the following exchange between reader and card is encrypted with NXP's proprietary CRYPTO1 stream cipher. The reader handles this, so your program still sees plain data.
  4. The access bits decide what is allowed. Authenticating with key A may allow reading but not writing, for example. Every operation is checked against the sector's access bits.
  5. One authentication covers one sector. Moving to another sector needs another authentication, possibly with different keys.

When authentication fails, the ACS readers answer 63 00, and PC/SC Part 3 also defines 69 82 ("security status not satisfied"). How a program should react is covered in handling 63 00 and 69 82, and the checklist for a failed test is in what a failed authentication means.

Both keys are 6 bytes (48 bits) and both live in the sector trailer: key A in bytes 0 to 5, key B in bytes 10 to 15. They are not ranked by strength. What each key may do comes only from the access bits.

Key AKey B
Required?Yes, every sector has oneOptional. If it is not needed, the access bits can make bytes 10 to 15 readable, and they become ordinary data.
Can it be read back?Never. Reading a trailer returns zeros for key A.Only if the access bits make it readable. When they do, NXP's data sheet says key B cannot be used for authentication in that sector.
Used in the transport configurationYes: new cards must be authenticated with key ANo: key B is readable there, so it cannot authenticate
Common design patternA "read" key given to many readersA "write" or "top-up" key kept for fewer, better-protected terminals

That last row is a pattern, not a rule built into the card. It only works if the access bits are set to match, for example data blocks that anyone with key A may read but only key B may write.

The access bits sit in bytes 6, 7 and 8 of each sector trailer. Byte 9 is a free user byte with the same access rights as the access bits. For each of the four blocks in the sector there are three bits, C1, C2 and C3, so 12 bits in all. The card stores each bit twice, once as it is and once inverted, which is why three bytes are needed. With each memory access, the card checks that every inverted copy matches. If it finds a mismatch, NXP's data sheet says the whole sector is irreversibly blocked.

The three bits mean different things for data blocks and for the trailer:

  • For a data block they choose which key may read, write, increment and decrement (key A, key B, either, or never). They also set whether the block is a plain read/write block or a value block (a 4-byte counter stored in a fixed, redundant format, used for purse-style balances).
  • For the sector trailer they choose who may write key A, who may read and write the access bits themselves, and who may read and write key B. Key A can never be read, whatever the bits say.

Some combinations are one-way doors. Several settings make the keys or the access bits "never" writable, and one makes data blocks unreadable and unwritable by any key. Choose such a setting and the sector cannot be changed back. NXP's data sheet (tables 7 and 8 of the MF1S50yyX/V1 document) lists all eight combinations for trailers and for data blocks. Use it as the reference, not a summary.

NXP's MIFARE Classic EV1 1K data sheet states that at delivery all keys are FF FF FF FF FF FF and bytes 6, 7 and 8 of each trailer are FF 07 80. Byte 9 is the user byte; on new cards it usually reads 69, which is why a factory trailer is often quoted as FF 07 80 69. The NXP data sheet itself only fixes bytes 6 to 8. So a new sector trailer looks like this (key A is shown as stored, although it reads back as zeros):

Bytes 0-5           Bytes 6-8   Byte 9   Bytes 10-15
FF FF FF FF FF FF   FF 07 80    69       FF FF FF FF FF FF
key A               access bits user     key B

Decoding the three access bytes shows what the factory setting allows. The high and low halves of each byte carry the bits for blocks 3, 2, 1, 0 (left to right):

ByteValueHigh half (bits 7-4)Low half (bits 3-0)
6FF = 1111 1111inverted C2 = 1111, so C2 = 0000inverted C1 = 1111, so C1 = 0000
707 = 0000 0111C1 = 0000 (matches byte 6)inverted C3 = 0111, so C3 = 1000
880 = 1000 0000C3 = 1000 (matches byte 7)C2 = 0000 (matches byte 6)

Reading the bits block by block gives C1 C2 C3 = 0 0 0 for data blocks 0, 1 and 2 and 0 0 1 for the trailer (block 3). According to NXP's tables, that means:

  • Data blocks (000): read, write, increment and decrement with key A or key B. In practice, with key A, because key B cannot authenticate here.
  • Trailer (001): key A may write key A, read and write the access bits, and read and write key B. Key B is readable, so it cannot authenticate.

So on a new card, key A FF FF FF FF FF FF unlocks everything, including the right to change the keys and the access bits. That is convenient for issuing cards and unsafe for using them.

Why the default keys must not stay in production

  • The factory key is public. It is printed in data sheets, reader manuals and tutorials, including ours.
  • In the transport configuration, anyone with any PC/SC reader can read and overwrite every data block. They could change a stored balance, a validity date or an ID number.
  • They can also rewrite the trailer. Someone else could set new keys or access bits and lock the system owner out of that sector for good.

Leaving default keys on issued cards is like shipping a door with the lock removed. Every card that goes into use should have keys that only the system knows.

What changing them involves (concept only)

Keys and access bits are changed by writing a new 16-byte block over the sector trailer. The program authenticates the sector with a key that the current access bits allow to write the trailer (key A, in the transport configuration). It then writes the new key A, the three access bytes with their inverted copies, the user byte and the new key B in one write. Finally it authenticates again with the new key to confirm. This is a card-issuing (personalisation) step, normally done once per card in a controlled place. BSD does not publish code for it, and the BSD Default Key utilities cannot change keys by design.

Wrong access bits lock a sector permanently

There is no undo. If the inverted copies in bytes 6 to 8 do not match, the card blocks the whole sector irreversibly. If the bits are valid but make the keys or access bits "never" writable, the sector is frozen in that state. If the new key is mistyped, lost or written to the wrong sector, nobody can authenticate that sector again. Before personalising real cards, design the access conditions on paper against NXP's tables. Have a second person check the bytes. Try the exact procedure on spare test cards, one sector at a time, and confirm each with a fresh authentication. Keep the keys in your key store before you write them to any card.

If every card in a system shares the same key, exposing that key from one card or one terminal exposes all of them. Key diversification avoids that. Each card gets its own keys, derived from a master (base) key and something unique to the card, usually its UID. The terminal does not store each card's key. It reads the UID, derives that card's key from the master key, and authenticates.

NXP describes the method in application note AN10922, "Symmetric key diversifications" (rev. 2.2, July 2019). Its points, in brief:

  • The diversified keys are written to each card when it is personalised, so every card holds different key values.
  • If one card's key is exposed, the damage stays with that card instead of the whole system.
  • The recommended algorithm is CMAC-based, for AES-128, AES-192 and 2-key/3-key TDEA (3DES) keys. NXP recommends at least the card's UID as diversification input, plus the key number and application (DESFire) or block number (MIFARE Plus).
  • The master key is best kept in a MIFARE SAM (AN10922 names the MIFARE SAM AV3), which can derive and use the diversified keys without ever releasing the master key.

AN10922 is written for MIFARE Plus and MIFARE DESFire keys. The same principle, per-card keys derived from a protected master key, is good practice for MIFARE Classic systems too. It limits the damage when one card's key leaks, but it does not remove the weaknesses of the Classic cipher described below.

A key is only as safe as the place it is stored. In order of preference:

WhereHow it worksNotes
A SAM in the readerA secure access module (a smart card chip in the reader's SAM slot) holds the master keys. The application asks the SAM to authenticate or derive keys, and the keys never appear in PC memory.The ACR1252U and ACR1552U have a SAM slot (see the ACR1252U SDK notes). BSD has not yet tested a SAM with these readers. Which SAM commands to use depends on the SAM product and its documentation.
A server or HSMKeys stay in a back-end service or a hardware security module. The terminal sends the card's UID or challenge data and receives only what it needs for that card and that session.Needs a reliable network. Combine with diversification so that a terminal never holds a master key.
Protected storage on the terminalIf keys must sit on the PC, encrypt them at rest with the operating system's key protection, restrict access to the service account, and load them only when needed.A fallback, not a goal. Anyone with administrator rights on the terminal can reach them.

Never put keys in client code. This includes a desktop .exe, a .NET assembly, an Android app, JavaScript or a plain configuration file. Compiled code is easy to decompile, and one leaked installer exposes every card. Also keep keys out of logs, screenshots, support tickets and source control. Use different keys for test and production cards. The factory key in our C# reading example is acceptable only because it is public and the example is for test cards.

ACS readers support this separation. Keys loaded with FF 82 into the volatile locations are cleared when the reader is unplugged. They live in the reader only as long as your session needs them.

MIFARE Classic protects its sectors with CRYPTO1, a proprietary NXP stream cipher with 48-bit keys. Since 2008, academic researchers have published weaknesses in the cipher and its use on the card. NXP's own position is plain. Its MIFARE Classic product page (checked 30 Nov 2026) refers customers who need security-relevant applications to the MIFARE DESFire and MIFARE Plus families instead. In practice:

  • MIFARE Classic remains usable where the card is only an identifier or the stakes are low, for example a library or simple membership card checked against a database.
  • It should not be the only protection for stored value, access to sensitive areas, or anything where a cloned or altered card causes real loss.
  • Good key management (changed keys, diversification, keys out of client code) is still necessary, but it does not make Crypto1 strong.
  • Keep the authoritative data on the server where you can. Treat the card as a pointer to an account, so a changed card value can be detected.

Migrating to MIFARE DESFire EV2 or EV3

MIFARE DESFire cards use standard cryptography (AES-128, as well as DES/3DES on older settings). They organise memory into applications and files, each with its own keys and access rights, and they speak ISO 7816-4 APDUs. NXP's current DESFire generation is EV3. Choose EV3, or EV2 where a system already uses it. A typical migration path:

  1. Inventory what the Classic cards store and which terminals read them.
  2. Check the readers. ACS PC/SC readers such as the ACR1252U and ACR1552U read both MIFARE Classic and DESFire, so both card types can run in parallel during the changeover. Our DESFire detection test shows how to confirm a DESFire card on an ACS reader.
  3. Design the DESFire application: files, keys (diversified), access rights, and where the keys are stored (SAM or server).
  4. Update the software to accept both card types, then issue DESFire cards to new users and as replacements.
  5. Retire the Classic cards by a fixed date, and remove Classic support from the terminals.

NXP also offers MIFARE Plus as a step-by-step upgrade path for existing Classic systems. BSD has not tested MIFARE Plus cards, so this page does not cover it further. For DESFire development with ACS readers, see the DESFire section of the SDK centre and our DESFire application development service. To buy DESFire or MIFARE Classic cards, see MIFARE cards.

Is the UID a key?

No. The UID is sent to any reader before authentication, so it identifies a card but proves nothing. Use it as an account number or as diversification input, never as the only check.

Can I read a card if I do not know its keys?

You can read the UID and the ATR, but no data from the protected sectors. If you have a legitimate need for the data, ask whoever issued the card for access. BSD does not provide, and will not help with, methods to find, guess or recover keys of cards you did not issue.

Does loading a key with FF 82 store it in the reader permanently?

Not with the volatile locations 00 and 01 used in our examples. The ACS manuals say they are cleared when the reader is disconnected.

Why does my card authenticate with key A but not key B?

In the transport configuration, key B is readable, and NXP's data sheet says a readable key B cannot authenticate. The card is doing what its access bits say.

Checked on 30 Nov 2026. Explanations are in BSD's own words.

BSD Infotech is an independent ACS supplier and integrator, not the manufacturer. ACS, the ACS logo and ACS product names belong to Advanced Card Systems Ltd. MIFARE, MIFARE Classic, MIFARE DESFire, MIFARE Plus and MIFARE SAM are trademarks of NXP B.V.

Planning keys for a card project?

Tell us the card type, the number of cards and how they are used. We help with key handling, DESFire applications and migration from MIFARE Classic on ACS readers.