コード例 #1
0
        /// <summary>
        /// Process the parameters of a Sequence. If a parameter of the same name is found in the list of parameters
        /// it overrides the XML parameter of the sequence
        /// </summary>
        /// <param name="seqParam">List of parameters</param>
        /// <param name="xmlSeqParam">Parameters of the XML sequence</param>
        /// <returns>The list of parameters to used to process the sequence of APDU commands</returns>
        private SequenceParameter ProcessParams(SequenceParameter seqParam, XmlAttributeCollection xmlSeqParam)
        {
            //Dictionary<string, string> l_seqParam = new Dictionary<string, string>();
            SequenceParameter l_seqParam = new SequenceParameter();

            int nNbParam = xmlSeqParam.Count;

            for (int nI = 0; nI < nNbParam; nI++)
            {
                XmlNode xNode = xmlSeqParam.Item(nI);

                string name = xNode.Name;
                string val  = xNode.Value;

                // Check if a val overrides the XML parameter of Sequence
                if (seqParam != null)
                {
                    try
                    {
                        val = seqParam[name];
                    }
                    catch
                    {
                    }
                }

                l_seqParam.Add(name, val);
            }

            return(l_seqParam);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            try
            {
                int    nbRecords = 10;
                string PIN       = "31323334FFFFFFFF";
                bool   bPin      = false;

                if (args.Length != 0)
                {
                    for (int nI = 0; nI < args.Length; nI++)
                    {
                        if (args[nI] == "P")
                        {
                            bPin = true;
                            PIN  = FormatPIN(args[++nI]);
                        }
                        else
                        {
                            nbRecords = int.Parse(args[nI]);
                        }
                    }
                }

                APDUResponse apduResp = null;
                CardNative   iCard    = new CardNative();

                string[] readers = iCard.ListReaders();

                iCard.Connect(readers[0], SHARE.Shared, PROTOCOL.T0orT1);

                APDUPlayer player = new APDUPlayer(iCard);
                player.LoadAPDUFile(Properties.Settings.Default.DataPath + ApduFile);
                player.LoadSequenceFile(Properties.Settings.Default.DataPath + SequenceFile);

                SequenceParameter seqParam = new SequenceParameter();

                // Process Apdu: VerifyCHV
                if (bPin)
                {
                    Console.WriteLine("Sequence: Verify CHV1");
                    seqParam.Add("PIN", PIN);
                    apduResp = player.ProcessSequence("Verify CHV1", seqParam);
                    Console.WriteLine(apduResp.ToString());
                }

                if (!bPin || (bPin && apduResp.Status == 0x9000))
                {
                    for (int nI = 1; nI <= nbRecords; nI++)
                    {
                        seqParam.Clear();
                        seqParam.Add("Record", nI.ToString());
                        //Console.WriteLine(string.Format("Read ADN, Record={0}", nI));
                        apduResp = player.ProcessSequence("Read ADN", seqParam);

                        PhoneNumber phone = new PhoneNumber(apduResp.Data);
                        Console.WriteLine("ADN n°" + nI.ToString());
                        Console.WriteLine(phone.ToString());
                        Console.WriteLine();

                        //Console.WriteLine(apduResp.ToString());
                    }
                }

                APDULogList log = player.Log;

                Console.WriteLine("Log:");
                APDULog[] arrayLog = log.ToArray();
                for (int nI = 0; nI < log.Count; nI++)
                {
                    Console.WriteLine(arrayLog[nI].ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: tsvx/SmartcardFramework
        static void Main(string[] args)
        {
            try
            {
                int nbRecords = 10;
                string PIN = "31323334FFFFFFFF";
                bool bPin = false;

                if (args.Length != 0)
                {
                    for (int nI = 0; nI < args.Length; nI++)
                    {
                        if (args[nI] == "P")
                        {
                            bPin = true;
                            PIN = FormatPIN(args[++nI]);
                        }
                        else
                            nbRecords = int.Parse(args[nI]);
                    }
                }

                APDUResponse apduResp = null;
                CardNative iCard = new CardNative();

                string[] readers = iCard.ListReaders();

                iCard.Connect(readers[0], SHARE.Shared, PROTOCOL.T0orT1);

                APDUPlayer player = new APDUPlayer(iCard);
                player.LoadAPDUFile(Properties.Settings.Default.DataPath + ApduFile);
                player.LoadSequenceFile(Properties.Settings.Default.DataPath + SequenceFile);

                SequenceParameter seqParam = new SequenceParameter();

                // Process Apdu: VerifyCHV
                if (bPin)
                {
                    Console.WriteLine("Sequence: Verify CHV1");
                    seqParam.Add("PIN", PIN);
                    apduResp = player.ProcessSequence("Verify CHV1", seqParam);
                    Console.WriteLine(apduResp.ToString());
                }

                if (!bPin || (bPin && apduResp.Status == 0x9000))
                {
                    for (int nI = 1; nI <= nbRecords; nI++)
                    {
                        seqParam.Clear();
                        seqParam.Add("Record", nI.ToString());
                        //Console.WriteLine(string.Format("Read ADN, Record={0}", nI));
                        apduResp = player.ProcessSequence("Read ADN", seqParam);

                        PhoneNumber phone = new PhoneNumber(apduResp.Data);
                        Console.WriteLine("ADN n°" + nI.ToString());
                        Console.WriteLine(phone.ToString());
                        Console.WriteLine();

                        //Console.WriteLine(apduResp.ToString());
                    }
                }

                APDULogList log = player.Log;

                Console.WriteLine("Log:");
                APDULog[] arrayLog = log.ToArray();
                for (int nI = 0; nI < log.Count; nI++)
                    Console.WriteLine(arrayLog[nI].ToString());

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }