public override void Authenticate(byte sector, MifareKeyType keyType, byte[] key) { // Load the factory MIFARE key into volatile memory myCard.OptionalCommands.LoadKeys(OptionalLoadKeyStructure.CardKey | OptionalLoadKeyStructure.Volatile, 0, (byte)keyType, key); // Authenticate to the sector if (keyType == MifareKeyType.KeyA) { myCard.OptionalCommands.GeneralAuthenticate(MifareProtocol.GetSectorTrailerBlock(sector), GeneralAuthenticateKeyType.KeyA, (byte)keyType); } else { myCard.OptionalCommands.GeneralAuthenticate(MifareProtocol.GetSectorTrailerBlock(sector), GeneralAuthenticateKeyType.KeyB, (byte)keyType); } }
/// <summary> /// This command allows the user to authenticate a credential. Before using this command the correct /// keys must have been loaded to the relevant key slot. /// </summary> /// <param name="address"> The Block number counted from 0 to [19 (MINI), 63 (1K), 127 (2K), 255 (4k)].</param> /// <returns></returns> public string GetMifareApdu(byte address, MifareKeyType keyType, byte keySlot) { return("FF8600000501" + "00" + address.ToString("X2") + ((byte)keyType).ToString("X2") + keySlot.ToString("X2")); }
public abstract void Authenticate(byte sector, MifareKeyType keyType, byte[] key);