/// <summary> /// /// </summary> /// <returns></returns> CardPinControl _GetVerifyChvPinControl() { CardCommandAPDU aVerifyChvAPDU = new CardCommandAPDU(0xA0, 0x20, 0x00, 0x01, CardHex.ToByteArray("FFFFFFFFFFFFFFFF")); CardPinControl aVerifyChvPinControl = new CardPinControl(aVerifyChvAPDU, CardPinEncoding.Ascii, 0); aVerifyChvPinControl.MinLength = 4; aVerifyChvPinControl.MaxLength = 4; return(aVerifyChvPinControl); }
/// <summary> /// /// </summary> /// <returns></returns> CardPinControl _GetChangeChvPinControl() { CardCommandAPDU aChangeChvAPDU = new CardCommandAPDU(0xA0, 0x24, 0x00, 0x01, CardHex.ToByteArray("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")); CardPinControl aChangeChvPinControl = new CardPinControl(aChangeChvAPDU, CardPinEncoding.Ascii, 0, 8); aChangeChvPinControl.MinLength = 4; aChangeChvPinControl.MaxLength = 4; return(aChangeChvPinControl); }
private void btnReadDetails_Click(object sender, System.EventArgs e) { if (aSim == null) { aSim = _ObtainSim(); if (aSim == null) { return; } } try { byte[] data = aSim.ReadIccIdentification(); if (data == null) { MessageBox.Show("Error reading GSM SIM card!"); _DisposeSim(aSim); aSim = null; return; } txtLog.AppendText("ICCID: " + CardHex.FromByteArray(data) + Environment.NewLine); /* check access to SIM card. fails if CHV required */ if (aSim.ReadImsi() == null) { CardResponseAPDU aRespAPDU = aSim.VerifyChv(this, m_aCardForm, "PIN Verification", "In order to access your SIM the PIN is required."); if (aRespAPDU == null) { // The PIN entry has been cancelled by the user. _DisposeSim(aSim); aSim = null; return; } if (!aRespAPDU.IsSuccessful) { string sHeading = "Failed to verify PIN!"; switch (aRespAPDU.SW) { case 0x9804: m_aCardForm.Notify(this, MessageBoxIcon.Warning, sHeading, "Wrong PIN!"); break; case 0x9840: m_aCardForm.Notify(this, MessageBoxIcon.Warning, sHeading, "Wrong PIN! The SIM has been blocked."); break; case 0x9808: m_aCardForm.Notify(this, MessageBoxIcon.Warning, sHeading, "The SIM is blocked. Please use mobile phone " + "in order to unblock the SIM with the PUK."); break; default: m_aCardForm.Notify(this, MessageBoxIcon.Warning, sHeading, "Unknown reason: (" + aRespAPDU.SW + ")"); break; } _DisposeSim(aSim); aSim = null; return; } } data = aSim.ReadImsi(); if (data == null) { MessageBox.Show("Error reading IMSI!"); _DisposeSim(aSim); aSim = null; return; } txtLog.AppendText("IMSI: " + CardHex.FromByteArray(data) + Environment.NewLine); if (!aSim.SelectDFTelecom()) { MessageBox.Show("Error selecting GSM file!"); _DisposeSim(aSim); aSim = null; return; } byte[] rand = CardHex.ToByteArray(txtRand.Text); byte[] resp = RunGsmAlgo(rand); /**/ } catch (Exception) { _DisposeSim(aSim); aSim = null; } }