mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-13 15:21:45 +01:00
61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
|
using NUnit.Framework;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Text;
|
|||
|
using NFC;
|
|||
|
using NFC.Readers.PCSC;
|
|||
|
using System.Threading;
|
|||
|
using NFC.Mifare_DESFire;
|
|||
|
using NFC.Mifare_DESFire.Enums;
|
|||
|
using NFC.ISO7816_4;
|
|||
|
using PCSC.Iso7816;
|
|||
|
using log4net.Config;
|
|||
|
|
|||
|
namespace NFC_Test
|
|||
|
{
|
|||
|
[TestFixture, Explicit]
|
|||
|
public class OTA
|
|||
|
{
|
|||
|
private string _ReaderID = "ACS ACR122U PICC Interface 0";
|
|||
|
|
|||
|
[Test]
|
|||
|
public void Init()
|
|||
|
{
|
|||
|
IHardware hardware = new Hardware();
|
|||
|
IReader reader = hardware.OpenReader(_ReaderID);
|
|||
|
|
|||
|
bool transmit_successfully = false;
|
|||
|
|
|||
|
ReaderEventHandler handler = (sender, card) =>
|
|||
|
{
|
|||
|
card.Connect();
|
|||
|
|
|||
|
MIFARE_DESFire_V2 desfire = new MIFARE_DESFire_V2(card);
|
|||
|
|
|||
|
desfire.AuthenticateISO_DES(0x00, desfire.GenerateEmptyKey(16));
|
|||
|
desfire.Format();
|
|||
|
|
|||
|
desfire.AuthenticateISO_DES(0x00, desfire.GenerateEmptyKey(16));
|
|||
|
|
|||
|
byte keySetting1 = desfire.GenerateKeySetting1(ChangeApplicationKey.MASTERKEY, ChangeMasterKeySettings.WITHMASTERKEY, CreateDeleteFile.NOKEY, FileDirectoryAccess.NOKEY, ChangeMasterKey.CHANGEABLE);
|
|||
|
byte keySetting2 = desfire.GenerateKeySetting2(CryptoOperationsType.AES, FileIdentifies.NOTUSED, 0x03);
|
|||
|
desfire.CreateApplication(0xAAFFEE, keySetting1, keySetting2);
|
|||
|
|
|||
|
desfire.SelectApplication(0xAAFFEE);
|
|||
|
|
|||
|
transmit_successfully = true;
|
|||
|
|
|||
|
card.Disconnect();
|
|||
|
};
|
|||
|
|
|||
|
reader.CardDiscovered += handler;
|
|||
|
reader.Start();
|
|||
|
|
|||
|
Assert.AreEqual(true, transmit_successfully);
|
|||
|
|
|||
|
reader.Stop();
|
|||
|
reader.CardDiscovered -= handler;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|