In order to change the access keys of a sector on a MIFARE Classic card, you simply have to update that sector's trailer block.
So, for instance, if your current key B is FFFFFFFFFFFF
(and the current access conditions permit writing of the sector trailer with key B), you would first authenticate for that sector with that current key B.
Then, you would create your new sector trailer:
<new key A> | access bits | general purpose byte | <new key B>
For instance:
AAAAAAAAAAAA 787788 69 BBBBBBBBBBBB
to have key A set to AAAAAAAAAAAA
and key B set to BBBBBBBBBBBB
with these access conditions:
- Trailer block: C1=0,C2=1,C3=1 → Sector trailer is writable using key B only; access bits/GPB can be read with key A or B.
- Data blocks: C1=1, C2=0, C3=0 → Write is possible using key B only; read is permitted with key A or B.
Finally, you can write the new sector trailer to the trailer block, which is the last block (i.e. block 3) of each sector.