-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAESencrypt.ino
83 lines (59 loc) · 2 KB
/
AESencrypt.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 AESencrypt
* @author Dr Aaron McConville
* @email [email protected]
* @date 2019/11/30
* @license GPL v3.0
*
**************************************************************************/
#include <AESLib.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";
unsigned char base64[100];
void setup() {
Serial.begin(115200);
while (!Serial);
nfc.begin();
}
void loop() {
if (c < 1) {
Serial.println("\n============================================");
Serial.println("Present card to generate encrypted 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);
String password = "password"; // <--------------- Plain Text Password (max 16 char)
int passLen = password.length();
while (passLen < 16) {
password = password + " ";
passLen = password.length();
}
char pass[password.length()];
password.toCharArray(pass, password.length());
aes128_enc_single(key, pass);
passLen = sizeof(pass);
encode_base64(pass, passLen, base64);
Serial.print("\nBase64 Encoded: "); Serial.println((char*)base64);
c = 0;
delay(2000);
}
}