Hello to All Arduino Members,
I am Doing a project by using AES Encryption.......
It's Everything Fine with 16bit data , the problem was occurs when i want to encrypt more than 16bit data,
my sample code and find bellow attached library file,
//#include<String.h>
#include <AES.h>
AES aes ;
byte key [] = "123458748785485" ;
byte plain [] = "Hello World Well Come to the ARDUINO World";
byte cipher [N_BLOCK] ;
byte check [N_BLOCK] ;
char edata[100],msgarray[500];
char * hex = "0123456789abcdef" ;
void clearbuf(char *b)// clearing the buffer
{
while(*b)
*b++='\0';
}
void clearbuf1(byte *b)// clearing the buffer
{
while(*b)
*b++='\0';
}
void setup ()
{
Serial.begin (9600) ;
Serial.println ("AES EBC Mode Checking") ;
encryption(plain);
}
byte encryption(byte d[150])
{
int i=0,j=0;
byte a[16],b[16];
aes.set_key (key, 128) ;
for( i=0;i<16;i++)
{
b[j++]=d[i];
}
b[i]='\0'; j=0;
aes.encrypt (d, cipher) ;
print_value(cipher,128);
clearbuf1(b);
clearbuf1(cipher);
for( i=16;i<sizeof(d);i++)
{
b[j++]=d[i];
}
b[i]='\0';
aes.set_key (key, 128) ;
aes.encrypt (b, cipher) ;
print_value(cipher,128);
clearbuf1(b);
Serial.print("DATA is: ");
Serial.println(msgarray);
}
void loop ()
{
;
}
void print_value (byte * a, int bits)
{
int j;
bits >>= 3 ;
for (int i = 0 ; i < bits ; i++)
{
byte b = a[i] ;
edata[j++] = hex [b>>4];
edata[j++] = hex [b&15];
// Serial.print (hex [b >> 4]) ;
// Serial.print (hex [b & 15]) ;
}
edata[j]='\0';
strcat(msgarray,edata);
clearbuf(edata);
// Serial.println () ;
}
In the above code I am trying to dividing 16bit data and individually encryption but finally i got the wrong hex decimal values .
I am trying one of encryption tool for to check my encryption data is correct or wrong by using this URL Online encrypt tool - Online tools
Kindly do the needful.
Thanks in advance.
AESlibrary.zip (43 KB)