Пример #1
0
        /// <summary>
        /// Wraps the PCSC function
        /// LONG SCardTransmit(
        ///		SCARDHANDLE hCard,
        ///		LPCSCARD_I0_REQUEST pioSendPci,
        ///		LPCBYTE pbSendBuffer,
        ///		DWORD cbSendLength,
        ///		LPSCARD_IO_REQUEST pioRecvPci,
        ///		LPBYTE pbRecvBuffer,
        ///		LPDWORD pcbRecvLength
        ///	);
        /// </summary>
        /// <param name="ApduCmd">APDUCommand object with the APDU to send to the card</param>
        /// <returns>An APDUResponse object with the response from the card</returns>
        public override APDUResponse Transmit(APDUCommand ApduCmd)
        {
            CSCardCmd   itfCmd  = new CSCardCmdClass();
            CByteBuffer itfData = new CByteBufferClass();
            int         nLe     = ApduCmd.Le;

            if (ApduCmd.Data == null)
            {
                itfData.SetSize(0);
            }
            else
            {
                int nWrite = 0;

                itfData.SetSize(ApduCmd.Data.Length);
                itfData.Write(ref ApduCmd.Data[0], ApduCmd.Data.Length, ref nWrite);
            }

            // Build the APDU command
            itfCmd.BuildCmd(ApduCmd.Class, ApduCmd.Ins, ApduCmd.P1, ApduCmd.P2, itfData, ref nLe);

            // Send the command
            m_itfCard.Transaction(ref itfCmd);

            // Analyse the response
            int nRead = 0;

            byte[] pbResp = new byte[itfCmd.ApduReplyLength];

            itfCmd.ApduReply.Read(ref pbResp[0], itfCmd.ApduReplyLength, ref nRead);

            return(new APDUResponse(pbResp));
        }
Пример #2
0
        /// <summary>
        /// Wraps the PCSC function
        /// LONG SCardTransmit(
        ///		SCARDHANDLE hCard,
        ///		LPCSCARD_I0_REQUEST pioSendPci,
        ///		LPCBYTE pbSendBuffer,
        ///		DWORD cbSendLength,
        ///		LPSCARD_IO_REQUEST pioRecvPci,
        ///		LPBYTE pbRecvBuffer,
        ///		LPDWORD pcbRecvLength
        ///	);
        /// </summary>
        /// <param name="ApduCmd">APDUCommand object with the APDU to send to the card</param>
        /// <returns>An APDUResponse object with the response from the card</returns>
        public override APDUResponse Transmit(APDUCommand ApduCmd)
        {
            CSCardCmd	itfCmd = new CSCardCmdClass();
            CByteBuffer	itfData = new CByteBufferClass();
            int	nLe = ApduCmd.Le;

            if (ApduCmd.Data == null)
            {
                itfData.SetSize(0);
            }
            else
            {
                int nWrite = 0;

                itfData.SetSize(ApduCmd.Data.Length);
                itfData.Write(ref ApduCmd.Data[0], ApduCmd.Data.Length, ref nWrite);
            }

            // Build the APDU command
            itfCmd.BuildCmd(ApduCmd.Class, ApduCmd.Ins, ApduCmd.P1, ApduCmd.P2, itfData, ref nLe);

            // Send the command
            m_itfCard.Transaction(ref itfCmd);

            // Analyse the response
            int nRead = 0;
            byte[]	pbResp = new byte[itfCmd.ApduReplyLength];

            itfCmd.ApduReply.Read(ref pbResp[0], itfCmd.ApduReplyLength, ref nRead);

            return new APDUResponse(pbResp);
        }