-
Notifications
You must be signed in to change notification settings - Fork 0
/
AESdecrypt.ino
83 lines (59 loc) · 1.94 KB
/
AESdecrypt.ino
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
/**************************************************************************
*
* @title AESdecrypt
* @author Dr Aaron McConville
* @email a.mcconville@ulster.ac.uk
* @date 2019/11/30
* @license GPL v3.0
*
**************************************************************************/
#include <AESLib.h>
#include <Base64.h>
#include "base64.hpp"
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);
int c = 0;
String uid = "0";
void setup() {
Serial.begin(115200);
while (!Serial);
nfc.begin();
}
void loop() {
if (c < 1) {
Serial.println("\n=================================");
Serial.println("Present card to decrypt password.");
Serial.println("=================================\n");
c++;
}
if (nfc.tagPresent())
{
NfcTag tag = nfc.read();
uid = tag.getUidString();
Serial.print("UID: "); Serial.println(uid);
uid.replace(" ", "");
Serial.print("Whitespace Removed: "); Serial.println(uid);
String uid2 = uid + uid;
char key[uid2.length()];
uid2.toCharArray(key, uid2.length());
Serial.print("Secret Key: "); Serial.println(key);
char pass[] = "O+2lNKO6JF98+L+3+ZBmhQ=="; // <--------------- Base64 Encoded Password
int passLen = sizeof(pass);
int decodedLen = base64_dec_len(pass, passLen);
char decoded[decodedLen];
base64_decode(decoded, pass, passLen);
Serial.print("\nBase64 Decoded: "); Serial.println(pass);
aes128_dec_single(key, decoded);
char * p = strchr(decoded, ' ');
if (p){
*p = 0;
}
Serial.print("Decrypted Password: "); Serial.println(decoded);
c = 0;
delay(2000);
}
}