Example #1
0
        private static async Task <byte[]> GetData(int sector, int blockInSector, byte[] keyA, byte[] keyB)
        {
            byte[] result = {};
            try
            {
                if (keyA != null)
                {
                    _card.AddOrUpdateSectorKeySet(new SectorKeySet {
                        KeyType = KeyType.KeyA, Sector = sector, Key = keyA
                    });
                }
                if (keyB != null)
                {
                    _card.AddOrUpdateSectorKeySet(new SectorKeySet {
                        KeyType = KeyType.KeyB, Sector = sector, Key = keyB
                    });
                }

                var sec = _card.GetSector(sector);
                result = await sec.GetData(blockInSector);
            }
            catch (Exception e)
            {
                WriteToLog($"GetData ERROR !!! {e}");
            }
            return(result);
        }
        public async Task <string> GetData()
        {
            return(await Task.Run(async() =>
            {
                try
                {
                    var s = connection.GetSector(sector);

                    var data = await connection.GetData(sector, 0, s.DataLength);

                    var name = Encoding.UTF8.GetString(data, 0, data.Length);

                    // We're reading the whole sector, remove trailing nulls
                    name = name.Replace("\0", "");
                    return name;
                }
                catch (Exception e)
                {
                    throw new SmartCardException("Could not authenticate to card", e);
                }
            }));
        }
Example #3
0
        private static async Task <List <byte[]> > ReadSector(int sector)
        {
            try
            {
                if (card == null)
                {
                    throw new Exception();
                }
                List <byte[]> blocks  = new List <byte[]>();
                var           _sector = card.GetSector(sector);
                for (int i = 0; i < _sector.NumDataBlocks; i++)
                {
                    var block = await _sector.GetData(i);

                    blocks.Add(block);
                }
                return(blocks);
            }
            catch
            {
                return(null);
            }
        }