public static Stream Select(SmartCard card, SelectType selectType, byte[] file, SelectFileOccurrence fileOccurrence, SelectFileControlInformation fileControlInformation, int expectedLength) { Command cmd = new Command(); cmd.Instruction = 0xA4; cmd.Parameter1 = (byte)selectType; cmd.Parameter2 = (byte)((byte)fileOccurrence | (byte)fileControlInformation); cmd.Data = file; cmd.ResponseLength = expectedLength; byte[] command = cmd.ToArray(); byte[] buffer = new byte[256]; //Console.Write("Sending command {0}...", BitConverter.ToString(command)); int len = card.Transmit(command, buffer); //Console.WriteLine(BitConverter.ToString(buffer, 0, len)); CommandStatus status = GetStatus(buffer, len); if (!status.IsNormal()) throw status.ToException(); Stream result = new MemoryStream(); result.Write(buffer, 0, len - 2); while (status.Sw1 == 0x61) { throw new NotImplementedException("Reading of remaining length not implemented"); } return result; }
public static Stream Select(SmartCard card, SelectType selectType, byte[] file, SelectFileOccurrence fileOccurrence, SelectFileControlInformation fileControlInformation, int expectedLength) { Command cmd = new Command(); cmd.Instruction = 0xA4; cmd.Parameter1 = (byte)selectType; cmd.Parameter2 = (byte)((byte)fileOccurrence | (byte)fileControlInformation); cmd.Data = file; cmd.ResponseLength = expectedLength; byte[] command = cmd.ToArray(); byte[] buffer = new byte[256]; //Console.Write("Sending command {0}...", BitConverter.ToString(command)); int len = card.Transmit(command, buffer); //Console.WriteLine(BitConverter.ToString(buffer, 0, len)); CommandStatus status = GetStatus(buffer, len); if (!status.IsNormal()) { throw status.ToException(); } Stream result = new MemoryStream(); result.Write(buffer, 0, len - 2); while (status.Sw1 == 0x61) { throw new NotImplementedException("Reading of remaining length not implemented"); } return(result); }