2010-08-22 12 views
1

Je travaille à une application pour lire la carte EMV en utilisant C#. J'utilise Winscard.dll. et j'ai établi la conncetion - Sélectionné le lecteur - se connecter à la carte et obtenir ATR. mais lors de l'envoi COMAND Slecetd application liste AIDE usin, je ne recive aucune donnée, je devrait recevoir SW1SW2 comme 61XX (où XX la longueur des données) j'ai envoyé la commande comme 00A4040007A0000000031010.commande Select AID ne fonctionne pas

Le code est:

// Private/Internal Types 
    [StructLayout(LayoutKind.Sequential)] 
    internal class SCARD_IO_REQUEST 
    { 
     internal uint dwProtocol; 
     internal int cbPciLength; 
     public SCARD_IO_REQUEST() 
     { 
      dwProtocol = 0; 
     } 
    } 

    public static IntPtr GetPciT0() 
    { 
     IntPtr handle = LoadLibrary("Winscard.dll"); 
     IntPtr pci = GetProcAddress(handle, "g_rgSCardT0Pci"); 
     FreeLibrary(handle); 
     return pci; 
    } 
    // public static byte[] GetSendBuffer(string cla, string ins , string p1 ,string p2 , string lc,string body) 

    public byte[] GetSendBuffer() 
    { 
     // Select application 00A4040007A0000000031010 
     string cla = "00"; 
     string ins = "A4"; 
     string p1 = "04"; 
     string p2 = "00"; 
     string lc = "07"; 
     string body = "A0000000031010"; 
     string script = String.Format("{0}{1}{2}{3}{4}{5}", cla, ins, p1, p2, 
     lc, body); 
     byte[] buffer = new byte[ script.Length/2]; 
     //Console.WriteLine("buffer {0}", buffer); 
     for (int i = 0; i < script.Length; i = i + 2) 
     { 

      string temp = script.Substring(i, 2); 
      buffer[i/2] = byte.Parse(temp, 
      System.Globalization.NumberStyles.HexNumber); 
     } 
     return buffer; 

    } 

// ================================= ==== ScardTransmit public void() { SCARD_IO_REQUEST ioRecv = new SCARD_IO_REQUEST(); octet [] pbRecvBuffer = nouvel octet [255]; int pcbRecvLength = 255; byte [] = pbsendBuffer this.GetSendBuffer();

int pbsendBufLen = pbsendBuffer.Length; 
ioRecv.cbPciLength = ioRecv.ToString().Length; 
IntPtr SCARD_PCI_T0 = GetPciT0(); 
uint uintret = SCardTransmit(pCardHandle, ref ioRecv, pbsendBuffer, 
pbsendBufLen, SCARD_PCI_T0, pbRecvBuffer, ref pcbRecvLength); 

}

+0

Code Beaucoup trop. Découpez ceci en un extrait minimal qui illustre le problème, puis décrivez le problème et posez votre question. – Timwi

+0

Merci, je compris onlt les fonctions a un problème, s'il vous plaît vérifier la fonction SCardTransmit car il n'a pas obtenu de rsult de données de sélection COMAND AID –

Répondre

0

juste essayer d'envoyer les éléments suivants:

0x00A4040000 

Cela devrait au moins quelque chose de retour. Les octets à la fin sont facultatifs. Ils servent un but mais juste voir si vous pouvez obtenir quelque chose de ce premier.

Questions connexes