Exemplo n.º 1
0
        private int AuthenticateBlock(int nBlock, int hCard)
        {
            _ioSendRequest = new ModWinsCard.SCARD_IO_REQUEST {
                dwProtocol = ModWinsCard.SCARD_PROTOCOL_UNDEFINED, cbPciLength = 8
            };

            _recvBuffLen = 0x02;

            _sentBuff = new byte[255];
            _recvBuff = new byte[255];

            _sentBuff = APDUCommands.AuthenticateBlock(nBlock);

            return(ModWinsCard.SCardTransmit(hCard, ref _ioSendRequest, ref _sentBuff[0], _sentBuff.Length, ref _ioSendRequest, ref _recvBuff[0], ref _recvBuffLen));
        }
Exemplo n.º 2
0
        private string GetUID()
        {
            string theCardUID = "";

            byte[] receivedUID = new byte[256];
            ModWinsCard.SCARD_IO_REQUEST request = new ModWinsCard.SCARD_IO_REQUEST();
            request.cbPciLength = System.Runtime.InteropServices.Marshal.SizeOf(typeof(ModWinsCard.SCARD_IO_REQUEST));
            request.dwProtocol  = ModWinsCard.SCARD_PROTOCOL_T1;
            byte[] sendBytes = new byte[] { 0xFF, 0xCA, 0x00, 0x00, 0x00 };
            int    outBytes  = receivedUID.Length;

            retCode = ModWinsCard.SCardTransmit(hCard, ref request, ref sendBytes[0], sendBytes.Length, ref request, ref receivedUID[0], ref outBytes);
            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                displayOut(1, retCode, "");
                System.Environment.Exit(0);
            }
            else
            {
                theCardUID = BitConverter.ToString(receivedUID.Take(4).ToArray()).Replace("-", string.Empty).ToLower();
            }
            return(theCardUID);
        }
        //only for mifare 1k cards
        private string getcardUID()
        {
            string cardUID = "";
            byte[] receivedUID = new byte[256];
            ModWinsCard.SCARD_IO_REQUEST request = new ModWinsCard.SCARD_IO_REQUEST();
            request.dwProtocol = ModWinsCard.SCARD_PROTOCOL_T1;
            request.cbPciLength = System.Runtime.InteropServices.Marshal.SizeOf(typeof(ModWinsCard.SCARD_IO_REQUEST));
            byte[] sendBytes = new byte[] { 0xFF, 0xCA, 0x00, 0x00, 0x00 }; //get UID command      for Mifare cards
            int outBytes = receivedUID.Length;
            int status = ModWinsCard.SCardTransmit(hCard, ref request, ref sendBytes[0], sendBytes.Length, ref request, ref receivedUID[0], ref outBytes);

            if (status != ModWinsCard.SCARD_S_SUCCESS)
            {
                cardUID = "Error";
            }
            else
            {
                cardUID = BitConverter.ToString(receivedUID.Take(4).ToArray()).Replace("-", string.Empty).ToLower();
            }
            return cardUID;
        }
Exemplo n.º 4
0
        private int AuthenticateBlock(int nBlock, int hCard)
        {
            _ioSendRequest = new ModWinsCard.SCARD_IO_REQUEST { dwProtocol = ModWinsCard.SCARD_PROTOCOL_UNDEFINED, cbPciLength = 8 };

            _recvBuffLen = 0x02;

            _sentBuff = new byte[255];
            _recvBuff = new byte[255];

            _sentBuff = APDUCommands.AuthenticateBlock(nBlock);

            return ModWinsCard.SCardTransmit(hCard, ref _ioSendRequest, ref _sentBuff[0], _sentBuff.Length, ref _ioSendRequest, ref _recvBuff[0], ref _recvBuffLen);
        }