/*
AES128 Básico
*/
#include <Crypto.h>
#include <AES.h>
#include <string.h>
//key[16] cotain 16 byte key(128 bit) for encryption
byte key[16]={0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
//plaintext[16] contain the text we need to encrypt
byte plaintext[16]={0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
//cypher[16] stores the encrypted text
byte cypher[16];
//decryptedtext[16] stores decrypted text after decryption
byte decryptedtext[16];
//creating an object of AES128 class
AES128 aes128;
void setup() {
Serial.begin(115200);
aes128.setKey(key,16);// Setting Key for AES
aes128.encryptBlock(cypher, plaintext);//cypher->output block and plaintext->input block
aes128.decryptBlock(decryptedtext, cypher);
// Print the key
Serial.print("key: ");
for (int i = 0; i < sizeof(key); ++i) {
if (key[i] < 0x10) {
Serial.print('0');
}
Serial.print(key[i], HEX);
Serial.print(' ');
}
Serial.println();
// Print the key
Serial.print("plaintext: ");
for (int i = 0; i < sizeof(plaintext); ++i) {
if (plaintext[i] < 0x10) {
Serial.print('0');
}
Serial.print(plaintext[i], HEX);
Serial.print(' ');
}
Serial.println();
// Print the cypher
Serial.print("cypher: ");
for (int i = 0; i < sizeof(cypher); ++i) {
if (cypher[i] < 0x10) {
Serial.print('0');
}
Serial.print(cypher[i], HEX);
Serial.print(' ');
}
Serial.println();
// Print the decryptedtext
Serial.print("decryptedtext: ");
for (int i = 0; i < sizeof(decryptedtext); ++i) {
if (decryptedtext[i] < 0x10) {
Serial.print('0');
}
Serial.print(decryptedtext[i], HEX);
Serial.print(' ');
}
Serial.println();
}
void loop() {
// put your main code here, to run repeatedly:
}