Closed Saeedsaeb closed 3 years ago
Hello again , this is the output i got from kakopappa , the KEY and IV has been copied from the code i did with this library https://github.com/kakopappa/arduino-esp8266-aes-lib
Booting...
Let's encrypt:
IV b64: 57n+xybi6YJScToUlcY2qA==
C1782BB6CFF3B64578EC12D68989AA3D
Encryption done!
Cipher size: 16
Encrypted data in base64: wXgrts/ztkV47BLWiYmqPQ==
Done...
the cipher is C1782BB6CFF3B64578EC12D68989AA3D wich is working fine , i dont know if know the library or not but this is my code in taht library , however i like to do this using this library , i put the codes so if i am wrong in a place u could tell me
#include "AES.h"
#include "base64.h"
AES aes;
uint8_t getrnd() {
uint8_t really_random = *(volatile uint8_t *)0x3FF20E44;
return really_random;
}
// Generate a random initialization vector
void gen_iv(byte *iv) {
for (int i = 0 ; i < N_BLOCK ; i++ ) {
iv[i]= (byte) getrnd();
}
}
void setup() {
Serial.begin(115200);
Serial.println("\nBooting...");
char b64data[200];
byte cipher[1000];
byte iv [N_BLOCK] ;
Serial.println("Let's encrypt:");
// Our AES key. Note that is the same that is used on the Node-Js side but as hex bytes.
// byte key[] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C };
byte key[] ={0xd8 , 0x40 , 0x2b , 0xd3 , 0x65 , 0xa3 , 0x4b , 0x4d , 0x34 , 0x72 , 0x9c , 0x3f , 0xa4 , 0x20 , 0x81 , 0x8b };
// The unitialized Initialization vector
// byte my_iv[N_BLOCK] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
byte my_iv[N_BLOCK] ={0xe7 , 0xb9 , 0xfe , 0xc7 , 0x26 , 0xe2 , 0xe9 , 0x82 , 0x52 , 0x71 , 0x3a , 0x14 , 0x95 , 0xc6 , 0x36 , 0xa8};
// Our message to encrypt. Static for this example.
char msg[] = "Hello World!";
aes.set_key( key , sizeof(key)); // Get the globally defined key
// gen_iv( my_iv ); // Generate a random IV
// Print the IV
base64_encode( b64data, (char *)my_iv, N_BLOCK);
Serial.println(" IV b64: " + String(b64data));
// Serial.println(" Message: " + msg );
// int b64len = base64_encode(b64data, (char *)msg.c_str(),msg.length());
// Serial.println (" Message in B64: " + String(b64data) );
// Serial.println (" The lenght is: " + String(b64len) );
// For sanity check purpose
//base64_decode( decoded , b64data , b64len );
//Serial.println("Decoded: " + String(decoded));
// Encrypt! With AES128, our key and IV, CBC and pkcs7 padding
// aes.do_aes_encrypt((byte *)b64data, b64len , cipher, key, 128, my_iv);
aes.do_aes_encrypt((byte *)msg, sizeof(msg) , cipher, key, 128, my_iv);
Serial.println();
Serial.println();
for(int i=0;i<aes.get_size();i++)
{
Serial.printf("%X",cipher[i]);
}
Serial.println();
Serial.println();
Serial.println("Encryption done!");
Serial.println("Cipher size: " + String(aes.get_size()));
base64_encode(b64data, (char *)cipher, aes.get_size() );
Serial.println ("Encrypted data in base64: " + String(b64data) );
Serial.println("Done...");
}
void loop() {
// put your main code here, to run repeatedly:
}
OK, so don't know why/how exactly but the encrypt function did accidentally include base64 conversion. It should not be there so I've removed it. After that change, the simple example forks as expected again.
Hello again , i have replace version 2.2.0 with version 2.2.1 The simple example dose not work i am trying to convert some text to AES and read the Cipher to do some comparison . but the output is not the same , i cant fgureout where i went wrong this is the data i must be working on : this have been made by nodejs
input data = Hello World! padding: CMS key: d8402bd365a34b4d34729c3fa420818b iv: e7b9fec726e2e98252713a1495c636a8 enc: c1782bb6cff3b64578ec12d68989aa3d this is my code:
this is the output :
and this is the output of simple example without any change (as is):
The example dose not work thanks