using PCSC.Iso7816; using System; using System.Collections.Generic; using System.Text; namespace NFC.Mifare_DESFire { public class MifareDESFire { /// /// Create new Application with AID /// /// Appilication ID public APDUCommand CreateApplication(UInt64 aid) { throw new NotImplementedException(); } public APDUCommand GetApplicationIDs() { APDUCommand cmd = new APDUCommand(IsoCase.Case2Short) { CLA = 0x90, INS = (byte)APDUInstructions.GET_APPLICATION_IDS }; return cmd; } public UInt32[] ConvertApplicationIDs(APDUResponse response) { if(response.Body.Length % 3 != 0) { throw new Exception("Invalid Body Length."); } List applicationIDs = new List(); for(int i = 0; i < response.Body.Length; i += 3) { UInt32 new_applicationID = 0; new_applicationID = (UInt32)((response.Body[i] << 16) + (response.Body[i + 1] << 8) + response.Body[i + 2]); applicationIDs.Add(new_applicationID); } return applicationIDs.ToArray(); } /// /// Select Application by ID /// /// 3 Byte ID public APDUCommand SelectApplication(UInt32 id) { byte[] id_byte = BitConverter.GetBytes(id); APDUCommand cmd = new APDUCommand(IsoCase.Case4Short) { CLA = 0x90, INS = (byte)APDUInstructions.SELECT_APPLICATION, Data = new byte[] { id_byte[0], id_byte[1], id_byte[2] }, Le = 0x00 }; return cmd; } /// /// Select Application by ID /// /// 3 Byte ID public APDUCommand CreateApplication(UInt32 id) { byte[] id_byte = BitConverter.GetBytes(id); APDUCommand cmd = new APDUCommand(IsoCase.Case4Short) { CLA = 0x90, INS = (byte)APDUInstructions.CREATE_APPLICATION, Data = new byte[] { id_byte[0], id_byte[1], id_byte[2] }, Le = 0x00 }; return cmd; } public byte GenerateKeySetting1() { return 0x00; } /// /// /// public enum ChangeKey : byte { MASTERKEY = 0x00, } } }