public bool A38(byte[] Rand, byte[] Result) { Debug.Assert(Rand.Length == 16); try { if (!DFgsm_selected) SelectDFGsm(); APDUResponse apduResp; APDUParam apduParam = new APDUParam(); //Execute A38 Algorithm apduParam.Data = (byte[])Rand.Clone(); apduRunGSM.Update(apduParam); apduResp = iCard.Transmit(apduRunGSM); if (apduResp.SW1 != SC_PENDING) throw new Exception("RunGSM: " + apduResp.ToString()); apduParam.Reset(); apduParam.Le = apduResp.SW2; apduParam.Data = null; apduGetResponse.Update(apduParam); apduResp = iCard.Transmit(apduGetResponse); if (apduResp.Status != SC_OK) throw new Exception("Get GSM result failed: " + apduResp.ToString()); //Console.Write("GSM Result: "); //for (int i = 0; i < apduResp.Data.Length; i++) // Console.Write(String.Format("{0:X2}", apduResp.Data[i])); //Console.WriteLine(); apduResp.Data.CopyTo(Result, 0); return true; } catch (System.Exception ex) { Console.WriteLine("SIM Run_GSM exception: " + ex.ToString()); return false; } }
/// <summary> /// This program tests the API with a SIM card. /// If your PIN is activated be careful when presenting the PIN to your card! /// </summary> public void Test() { try { DFgsm_selected = false; APDUResponse apduResp; APDUParam apduParam = new APDUParam(); // Verify the PIN (if necessary) byte[] pin = new byte[] { 0x31, 0x32, 0x33, 0x34, 0xFF, 0xFF, 0xFF, 0xFF }; apduParam.Data = pin; apduVerifyCHV.Update(apduParam); apduResp = iCard.Transmit(apduVerifyCHV); // Select the MF (3F00) apduParam.Data = new byte[] { 0x3F, 0x00 }; apduSelectFile.Update(apduParam); apduResp = iCard.Transmit(apduSelectFile); if (apduResp.Status != SC_OK && apduResp.SW1 != SC_PENDING) throw new Exception("Select command failed: " + apduResp.ToString()); Console.WriteLine("MF selected"); // Select the EFtelecom (7F10) apduParam.Data = new byte[] { 0x7F, 0x10 }; apduSelectFile.Update(apduParam); apduResp = iCard.Transmit(apduSelectFile); if (apduResp.Status != SC_OK && apduResp.SW1 != SC_PENDING) throw new Exception("Select command failed: " + apduResp.ToString()); Console.WriteLine("DFtelecom selected"); // Select the EFadn (6F3A) apduParam.Data = new byte[] { 0x6F, 0x3A }; apduSelectFile.Update(apduParam); apduResp = iCard.Transmit(apduSelectFile); if (apduResp.Status != SC_OK && apduResp.SW1 != SC_PENDING) throw new Exception("Select command failed: " + apduResp.ToString()); Console.WriteLine("EFadn (Phone numbers) selected"); // Read the response if (apduResp.SW1 == SC_PENDING) { apduParam.Reset(); apduParam.Le = apduResp.SW2; apduParam.Data = null; apduGetResponse.Update(apduParam); apduResp = iCard.Transmit(apduGetResponse); if (apduResp.Status != SC_OK) throw new Exception("Select command failed: " + apduResp.ToString()); } // Get the length of the record int recordLength = apduResp.Data[14]; Console.WriteLine("Reading the Phone number 10 first entries"); // Read the 10 first record of the file for (int nI = 0; nI < 10; nI++) { apduParam.Reset(); apduParam.Le = (byte) recordLength; apduParam.P1 = (byte) (nI + 1); apduReadRecord.Update(apduParam); apduResp = iCard.Transmit(apduReadRecord); if (apduResp.Status != SC_OK) throw new Exception("ReadRecord command failed: " + apduResp.ToString()); Console.WriteLine("Record #" + ((int) (nI + 1)).ToString()); Console.WriteLine(apduResp.ToString()); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }