private static byte[] getEF(byte[] apduSelectMF) { logger.Debug("getEF"); byte[] certDER = null; try { using (var reader = new ICReader()) { // CONNECT if (reader.Connect() == false) { throw (new Exception("Connect Error")); } // SELECT AP if (reader.SendandResponse(APDU_SELECT_AP).IsSuccess == false) { throw (new Exception("SELECT AP Error")); } // select MF if (reader.SendandResponse(apduSelectMF).IsSuccess == false) { throw (new Exception("SELECT MF Error")); } // READ Cert certDER = readCert(reader); } } catch (Exception ex) { logger.Error(ex); } return(certDER); }
public static bool IsJPKICardExist() { logger.Debug("IsJPKICardExist"); bool ret = false; try { using (var reader = new ICReader()) { // CONNECT if (reader.Connect() == false) { throw (new Exception("Connect Error")); } // SELECT AP if (reader.SendandResponse(APDU_SELECT_AP).IsSuccess == false) { throw (new Exception("SELECT AP Error")); } } ret = true; } catch (Exception ex) { logger.Error(ex); } return(ret); }
private static byte[] getEFwidhPIN(byte[] apduSelectMF, byte[] apduSelectPIN, string pin) { logger.Debug("getEFwidhPIN"); byte[] certDER = null; try { using (var reader = new ICReader()) { // CONNECT if (reader.Connect() == false) { throw (new Exception("Connect Error")); } // SELECT AP if (reader.SendandResponse(APDU_SELECT_AP).IsSuccess == false) { throw (new Exception("SELECT AP Error")); } // SELECT PIN IDF if (reader.SendandResponse(apduSelectPIN).IsSuccess == false) { throw (new Exception("SELECT PIN IDF Error")); } // VERIFY PIN { byte[] pinbyte = System.Text.Encoding.ASCII.GetBytes(pin); var apdu = new List <byte>(); apdu.AddRange(new List <byte> { 0x00, 0x20, 0x00, 0x80 }); apdu.Add((byte)pinbyte.Length); apdu.AddRange(pinbyte.ToList()); // send if (reader.SendandResponse(apdu.ToArray()).IsSuccess == false) { throw (new Exception("VERIFY PIN Error")); } } // select MF if (reader.SendandResponse(apduSelectMF).IsSuccess == false) { throw (new Exception("SELECT MF Error")); } // READ Cert certDER = readCert(reader); } } catch (Exception ex) { logger.Error(ex); } return(certDER); }
private static int getPINRetryCount(byte[] apduSelectMF) { logger.Debug("<<<getPINRetryCount>>>"); int retrycount = -1; try { using (var reader = new ICReader()) { // CONNECT if (reader.Connect() == false) { throw (new Exception("Connect Error")); } // SELECT AP if (reader.SendandResponse(APDU_SELECT_AP).IsSuccess == false) { throw (new Exception("SELECT AP Error")); } // SELECT MF if (reader.SendandResponse(apduSelectMF).IsSuccess == false) { throw (new Exception("SELECT MF Error")); } // VERIFY var res = reader.SendandResponse(new byte[] { 0x00, 0x20, 0x00, 0x80 }); if (res.Sw1 == 0x63) { retrycount = res.Sw2 & 0xF; } } } catch (Exception ex) { logger.Error(ex); return(-9); } return(retrycount); }
public static byte[] GetCardUID() { logger.Debug("<<<GetCardUID>>>"); byte[] uid = null; try { using (var reader = new ICReader()) { // CONNECT if (reader.Connect() == false) { throw (new Exception("Connect Error")); } // get UID var response = reader.SendandResponse(new byte[] { 0xFF, 0xCA, 0x00, 0x00, 0x00 }); if (response.IsSuccess) { uid = response.Data; } } } catch (Exception ex) { logger.Debug(ex); } return(uid); }
private static byte[] signature(string pin, byte[] digestSHA1, byte[] apduSelectPIN, byte[] apduSelectKey) { byte[] signature = null; try { if (pin.Length <= 0) { throw new Exception("Error PIN_REQUIRED"); } logger.Debug("DIGEST SHA1 ---"); logger.Debug(Common.BytesToHexString(digestSHA1)); logger.Debug("--- DIGEST SHA1"); var digestInfo = createDigestInfo(digestSHA1); logger.Debug("DIGESTINFO ---"); logger.Debug(Common.BytesToHexString(digestInfo)); logger.Debug("--- DIGESTINFO"); using (var reader = new ICReader()) { // CONNECT if (reader.Connect() == false) { throw (new Exception("Connect Error")); } // SELECT AP if (reader.SendandResponse(APDU_SELECT_AP).IsSuccess == false) { throw (new Exception("SELECT AP Error")); } // SELECT PIN IDF if (reader.SendandResponse(apduSelectPIN).IsSuccess == false) { throw (new Exception("SELECT PIN IDF Error")); } // VERIFY PIN { byte[] pinbyte = System.Text.Encoding.ASCII.GetBytes(pin); var apdu = new List <byte>(); apdu.AddRange(new List <byte> { 0x00, 0x20, 0x00, 0x80 }); apdu.Add((byte)pinbyte.Length); apdu.AddRange(pinbyte.ToList()); // send if (reader.SendandResponse(apdu.ToArray()).IsSuccess == false) { throw (new Exception("VERIFY PIN Error")); } } // SELECT 秘密鍵IEF if (reader.SendandResponse(apduSelectKey).IsSuccess == false) { throw (new Exception("SELECT MF Error")); } // COMPUTE DIGITAL SIGNATURE // < 80 2A 00 80 [DigestInfo] // > [SIGNATURE] { var apdu = new List <byte>(); apdu.AddRange(new List <byte> { 0x80, 0x2A, 0x00, 0x80 }); apdu.Add((byte)digestInfo.Length); apdu.AddRange(digestInfo.ToList()); apdu.Add((byte)0x00); var res = reader.SendandResponse(apdu.ToArray()); if (res.IsSuccess == false) { throw (new Exception("SIGNATURE Error")); } signature = res.Data; } } } catch (Exception ex) { logger.Debug(ex); } return(signature); }