/// <summary> /// Gets the default card reader. /// </summary> /// <returns></returns> public CardReader GetReader() { CardReader result = GetReader(NativeMethods.GetSelectedReaderIndex()); if (result == null) { result = GetReader(0); } return(result); }
/// <summary> /// Decrypts the file. /// </summary> /// <param name="reader">The reader.</param> /// <param name="source">The source.</param> /// <param name="destination">The destination.</param> /// <returns></returns> public static bool DecryptFile(CardReader reader, string source, string destination) { if (reader != null) { NativeMethods.SelectReaderByName(reader.Name); return(NativeMethods.CardDecryptFile(source, destination)); } else { return(false); } }
/// <summary> /// Retrieves the readers list from the native engine library. /// </summary> private void RetrieveReadersList() { ClearReadersList(); for (int i = 0; i < NativeMethods.GetReadersCount(); i++) { int len = NativeMethods.GetReaderNameLen(i) / 2; StringBuilder sb = new StringBuilder(len); NativeMethods.GetReaderName(i, sb, len); CardReader reader = new CardReader(); reader.Name = sb.ToString(); reader.Index = i; readers.Add(reader); } }
public bool SendAPDU(int readerNumber, byte[] apdu, int apduLen, byte[] result, ref int len) { CardReader reader = GetReader(readerNumber); if (reader == null) { return(false); } Card card = reader.GetCard(); if (card == null) { return(false); } return(NativeMethods.SendAPDU(readerNumber, apdu, apduLen, result, ref len)); }
/// <summary> /// Setting up the trace of the card events handler /// </summary> /// <param name="readerNumber">The reader number.</param> /// <param name="eventCode">The event code.</param> /// <param name="userContext">The user context.</param> private void EventTracer(ref int readerNumber, ref int eventCode, IntPtr userContext) { switch ((CardEvent)eventCode) { case CardEvent.CardInsert: if (CardInserted != null) { CardInserted(this, new CardEventArgs((int)readerNumber)); } break; case CardEvent.CardRemove: if (CardRemoved != null) { CardRemoved(this, new CardEventArgs((int)readerNumber)); CardReader reader = GetReader(readerNumber); if (reader != null) { reader.DeactivateCard(); } } break; case CardEvent.ReadersChange: ReloadReadersList(); if (ReadersListChanged != null) { ReadersListChanged(this, EventArgs.Empty); } break; case CardEvent.UnknownEvent: break; default: break; } }
/// <summary> /// Generates the authentication signature. /// </summary> /// <param name="reader">The reader.</param> /// <param name="pinCode">The pin code.</param> /// <param name="dataHash">The data hash.</param> /// <param name="hashSize">Size of the hash.</param> /// <returns></returns> public static byte[] GenerateAuthenticationSignature(CardReader reader, string pinCode, byte[] dataHash, int hashSize) { if (reader != null) { int index = NativeMethods.GetReaderIndex(reader.Name); byte[] signature = new byte[1024]; int signatureSize = 1024; if (NativeMethods.GenerateAuthenticationSignatureEx(index, pinCode, dataHash, hashSize, signature, ref signatureSize)) { byte[] result = new byte[signatureSize]; Array.Copy(signature, result, signatureSize); return(result); } else { return(null); } } else { return(null); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> internal void Dispose(bool disposing) { reader = null; }
/// <summary> /// Initializes a new instance of the <see cref="Card"/> class. /// </summary> /// <param name="reader">The reader.</param> internal Card(CardReader reader) { this.reader = reader; }