Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using uFR;
namespace uFR_AES_tester
{
using DL_STATUS = System.UInt32;
public partial class Form1 : Form
{
DL_STATUS status;
public Form1()
{
InitializeComponent();
}
public static byte[] StringToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}
private void bStoreAESKeyIntoReader_Click(object sender, EventArgs e)
{
byte[] aes_key = new byte[16];
byte aes_key_no = Byte.Parse(InternalKeyNumberCB.Text);
aes_key = StringToByteArray(AesKeyInternalTB.Text);
status = (UInt32)uFCoder.uFR_int_DesfireWriteAesKey(aes_key_no, aes_key);
if (status == 0)
{
StatusLabel.Text = "Operation completed";
StatusRTB.Text = "uFR_int_DesfireWriteAesKey = " + uFCoder.status2str((uFR.DL_STATUS)status);
}
else
{
StatusLabel.Text = uFCoder.status2str((uFR.DL_STATUS)status);
StatusRTB.Text = "uFR_int_DesfireWriteAesKey = " + uFCoder.status2str((uFR.DL_STATUS)status);
}
}
private void bInternalKeysLock_Click(object sender, EventArgs e)
{
String pass = PasswordTB.Text;
if (pass.Length != 8)
{
MessageBox.Show("Pasword must be 8 character length");
}
else
{
status = (UInt32)uFCoder.ReaderKeysLock(pass.ToCharArray());
if (status == 0)
{
StatusLabel.Text = "Operation completed";
StatusRTB.Text = "ReaderKeysLock = " + uFCoder.status2str((uFR.DL_STATUS)status);
}
else
{
StatusLabel.Text = "Operation not completed";
StatusRTB.Text = "ReaderKeysLock = " + uFCoder.status2str((uFR.DL_STATUS)status);
}
}
}
private void bInternalKeysUnlock_Click(object sender, EventArgs e)
{
String pass = PasswordTB.Text;
if (pass.Length != 8)
{
MessageBox.Show("Pasword must be 8 character length");
}
else
{
status = (UInt32)uFCoder.ReaderKeysUnlock(pass.ToCharArray());
if (status == 0)
{
StatusLabel.Text = "Operation completed";
StatusRTB.Text = "ReaderKeysUnlock = " + uFCoder.status2str((uFR.DL_STATUS)status);
}
else
{
StatusLabel.Text = uFCoder.status2str((uFR.DL_STATUS)status); ;
StatusRTB.Text = "ReaderKeysUnlock = " + uFCoder.status2str((uFR.DL_STATUS)status);
}
}
}
private void bChangeAesKeyCard_Click(object sender, EventArgs e)
{
byte[] old_key = new byte[16];
byte[] new_key = new byte[16];
byte aid_key_no = Byte.Parse(AIDKeyNrChangeCH.Text);
UInt16 card_status;
UInt16 exec_time;
old_key = StringToByteArray(OldKeyTB.Text);
new_key = StringToByteArray(NewKeyTB.Text);
if (UseInternal.Checked == true)
{
byte aes_key_nr = Byte.Parse(InternalKeyNumberAuth.Text);
UInt32 aid = Convert.ToUInt32(AIDCardAuth.Text, 16);
byte aid_key_nr_auth = Byte.Parse(AIDKeyNrAuth.Text);
status = (UInt32)uFCoder.uFR_int_DesfireChangeAesKey(aes_key_nr, aid, aid_key_nr_auth, new_key, aid_key_no, old_key, out card_status, out exec_time);
}
else
{
byte[] aes_key_ext = new byte[16];
aes_key_ext = StringToByteArray(AESkeyTB.Text);
UInt32 aid = Convert.ToUInt32(AIDCardAuth.Text, 16);
byte aid_key_nr_auth = Byte.Parse(AIDKeyNrAuth.Text);
status = (UInt32)uFCoder.uFR_int_DesfireChangeAesKey_PK(aes_key_ext, aid, aid_key_nr_auth, new_key, aid_key_no, old_key, out card_status, out exec_time);
}
if (status == 0)
{
StatusLabel.Text = "Operation completed";
StatusRTB.Text = "uFR_int_DesfireChangeAesKey = " + uFCoder.status2str((uFR.DL_STATUS)status);
if (card_status == (UInt16)DESFIRE_CARD_STATUS_CODES.CARD_OPERATION_OK)
{
StatusRTB.Text += "\nCard status : CARD_OPERATION_OK\nExecution time : " + exec_time.ToString() + " ms";
}
else
{
StatusLabel.Text = Enum.GetName(typeof(DESFIRE_CARD_STATUS_CODES), card_status);
StatusRTB.Text += "\nCard status : " + Enum.GetName(typeof(DESFIRE_CARD_STATUS_CODES), card_status) + "\nExecution time : " + exec_time.ToString() + " ms";
}
}
else
{
StatusLabel.Text = uFCoder.status2str((uFR.DL_STATUS)status);
StatusRTB.Text = "uFR_int_DesfireChangeAesKey = " + uFCoder.status2str((uFR.DL_STATUS)status) +
"\nExecution time : " + exec_time.ToString() + " ms";
}
}
private void bGetKeySettings_Click(object sender, EventArgs e)
{
UInt32 aid = Convert.ToUInt32(AIDCardAuth.Text, 16);
byte setting;
byte set_temp = 0;
byte max_key_no;
UInt16 card_status;
UInt16 exec_time;
if (UseInternal.Checked == true)
{
byte aes_key_nr = Byte.Parse(InternalKeyNumberAuth.Text);
status = (UInt32)uFCoder.uFR_int_DesfireGetKeySettings(aes_key_nr, aid, out setting, out max_key_no, out card_status, out exec_time);
}
else
{
byte[] aes_key_ext = new byte[16];
aes_key_ext = StringToByteArray(AESkeyTB.Text);
status = (UInt32)uFCoder.uFR_int_DesfireGetKeySettings_PK(aes_key_ext, aid, out setting, out max_key_no, out card_status, out exec_time);
}
if (status == 0)
{
StatusLabel.Text = "Operation completed";
StatusRTB.Text = "uFR_int_DesfireGetKeySettings = " + uFCoder.status2str((uFR.DL_STATUS)status);
if (card_status == (UInt16)DESFIRE_CARD_STATUS_CODES.CARD_OPERATION_OK)
{
StatusRTB.Text += "\nCard status : CARD_OPERATION_OK\nExecution time : " + exec_time.ToString() + " ms";
StatusRTB.Text += "\n\nMax key number : " + max_key_no.ToString();
setting &= 0x0F;
switch (setting)
{
case (byte)DESFIRE_KEY_SETTINGS.DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_CHANGE_KEY_CHANGE:
set_temp = 0;
break;
case (byte)DESFIRE_KEY_SETTINGS.DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_CHANGE_KEY_NOT_CHANGE:
Loading full blame...