Hello,
I came by most of this code on the forum after searching for long. I tried to modified it but unfortunately the decrypted text is incorrect. I am using AES in ECB mode
#include <Crypto.h>
#include <AES.h>
String RawData = "21.224959807829812,72.80706712431909,8043,5983,7585,8591,4889,9247";
AES256 Aes256;
BlockCipher* Cipher = &Aes256;
void setup()
{
Serial1.begin(9600);
byte Plaintext[RawData.length()];
RawData.getBytes(Plaintext, RawData.length());
byte Key[32] = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8};
crypto_feed_watchdog();
// Set the Encryption key
Cipher->setKey(Key, Cipher->keySize());
byte EncryptedBuffer[RawData.length()];
byte DecryptedBuffer[RawData.length()];
// Encryption
Cipher->encryptBlock(EncryptedBuffer, Plaintext);
// Print Original Data
Serial1.print("Original Data: ");
Serial1.println(reinterpret_cast<char*>(Plaintext));
// Decryption
Cipher->setKey(Key, Cipher->keySize());
Cipher->decryptBlock(DecryptedBuffer, EncryptedBuffer);
// Print decrypted data
Serial1.print("Decrypted Data: ");
Serial1.println((char*)DecryptedBuffer);
}
void loop()
{
}
The result is
Original Data: 21.224959807829812,72.80706712431909,8043,5983,7585,8591,4889,924
Decrypted Data: 21.2249598078298
I believe I am missing something for block encryption. All help is appreciated.