// AES128 CBC Encrypt/Decrypt with no initial vector
#include <CryptoAES_CBC.h>
#include <AES.h>
#include <string.h>
//key[16] cotain 16 byte key(128 bit) for encryption
byte key[16] = {0x7D,0x69,0xFA,0x5E,0x85,0x21,0xCD,0xE9,0xFC,0x98,0x7C,0x36,0x05,0x73,0xD5,0xCB};
//plaintext[16] contain the text we need to encrypt
byte plaintext[16] = "1";
//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;
int x;
void setup()
{
Serial.begin(115200);
aes128.setKey(key,16);// Setting Key for AES
Serial.print("Before Encryption: ");
for(int i=0; i<sizeof(plaintext); i++){
Serial.write(plaintext[i]);
}
aes128.encryptBlock(cypher,plaintext);//cypher->output block and plaintext->input block
Serial.println();
Serial.print("After Encryption : ");
for(int j=0;j<=15;j++)
{
x = int(cypher[j]);
if(x<=15)
Serial.print("0");
Serial.print(x , HEX);
}
aes128.decryptBlock(decryptedtext,cypher);
Serial.println();
Serial.print("After Decryption : ");
for(int i=0; i<sizeof(decryptedtext); i++){
Serial.write(decryptedtext[i]);
}
}
void loop()
{
// put your main code here, to run repeatedly:
}