AES encryption to decryption not outputting correctly

Hey all I am having the hardest time trying to figure out how to go about the order of decryption the encrypted text.

This is my sketch code:

#include "AES.h"
#include "base64.h"

AES aes;

void gen_iv(byte  *iv) {
    for (int i = 0 ; i < N_BLOCK ; i++ ) {
        iv[i]= (byte) *(volatile uint8_t *)0x3FF20E44;
    }
}

void setup() {
  Serial.begin(115200);
    Serial.println("\nBooting...");  

    char b64data[2000];
    byte cipher[1000];
    byte iv [N_BLOCK];
    char *encodedFinal;

    Serial.println("Let's encrypt:");

    byte *key = (unsigned char*)"5TGB&YHN7UJM(IK<";
    byte *my_iv = (unsigned char*)"!QAZ2WSX#EDC4RFV";
    char *msg = "{\"data\":{\"value\":300}, \"SEQN\":700 , \"msg\":\"IT WORKS!!\" }";

    //Set the key for AES
    aes.set_key(key, sizeof(key));

    /*
    ==================================================================
    Encoding section
    ==================================================================
    */

    //Encode IV to Base64
    base64_encode(b64data, (char *)my_iv, N_BLOCK);    
    Serial.println("      IV -> Base64: " + String(b64data));
    Serial.println("       Orignal Msg: " + String(msg));

    //Encode message into Base64
    int b64len = base64_encode(b64data, (char *)msg, String(msg).length());
    Serial.println(" Message -> Base64: " + String(b64data));

    // Encrypt into AES256   
    aes.do_aes_encrypt((byte *)b64data, b64len , cipher, key, 256, my_iv);
    Serial.println("Encrypted: " + String(b64data));

    //Encode everything now in Base64
    base64_encode(b64data, (char *)cipher, aes.get_size());
    Serial.println("Encrypted -> Base64: " + String(b64data));
    encodedFinal = (char*)b64data;
    Serial.println("Final encoded: " + String(encodedFinal));

    /*
    ==================================================================
    Decoding section
    ==================================================================
    */

Serial.println();
  Serial.println();
    Serial.println();
      Serial.println();
    //Decoding everything from Base64
    char b64dataDecode[2000];
    byte cipherDecode[1000];

    //Decode from Base64 to Encrypted msg
    base64_decode(b64dataDecode, (char *)encodedFinal, aes.get_size());
    Serial.println(" Base64 -> Encrypted: " + String(b64dataDecode));

    //Decoding from Encrypted
    aes.do_aes_decrypt((byte *)encodedFinal, base64_dec_len(encodedFinal, String(encodedFinal).length()), cipherDecode, key, 256, my_iv);
    Serial.println("Encrypted -> Original Msg: ") + String(encodedFinal);

    Serial.println("Done...");
}

void loop() {
  // put your main code here, to run repeatedly:

}

And this is the output I get:

Booting...
Let's encrypt:
IV -> Base64: IVFBWjJXU1gjRURDNFJGVg==
Orignal Msg: {"data":{"value":300}, "SEQN":700 , "msg":"IT WORKS!!" }
Message -> Base64: eyJkYXRhIjp7InZhbHVlIjozMDB9LCAiU0VRTiI6NzAwICwgIm1zZyI6IklUIFdPUktTISEiIH0=
Encrypted: eyJkYXRhIjp7InZhbHVlIjozMDB9LCAiU0VRTiI6NzAwICwgIm1zZyI6IklUIFdPUktTISEiIH0=
Encrypted -> Base64: sD9f8LnxQrlOvTODLbzXPM5wWMk6+KnpmGiowTtKswGK80+yf9DyHjjiF94TwUpP/1V4f9KsHA7+1oAmBy12Dl8Dvk/ZclFvNeNrXSwCFlU=
Final encoded: sD9f8LnxQrlOvTODLbzXPM5wWMk6+KnpmGiowTtKswGK80+yf9DyHjjiF94TwUpP/1V4f9KsHA7+1oAmBy12Dl8Dvk/ZclFvNeNrXSwCFlU=

Base64 -> Encrypted: ⸮?_⸮⸮B⸮N⸮3⸮-⸮⸮<⸮pX⸮:⸮⸮⸮h⸮⸮;J⸮⸮⸮O⸮⸮⸮8⸮⸮⸮JO⸮UxҬ⸮ր&
Encrypted -> Original Msg:
Done...

As you can see above, the decryption is not working correctly. The encryption works just fine though (but i think the Encoding part is not coming out correctly since its the same as the Base64 encoding?).

Help would be great in order to solve this issue!

What arduino are you using?

It looks like you are :

creating a plain text string
converting it to base 64
encrypting it
converting the encrypted text to base 64

then reversing the whole procedure to get back to the original plain text.

It looks like you are printing the b64data twice, once with the prefix "Message -> Base64:" and next with the prefix "Encrypted: "

For testing, maybe try simplifying it by immediately decrypting the text after the encryption and print it out to see that that bit works.

Your array sizes are huge and for testing on say a Uno make the 4 big arrays global and reduce the size to one tenth of their original size.

6v6gt:
Your array sizes are huge and for testing on say a Uno make the 4 big arrays global and reduce the size to one tenth of their original size.

Indeed hence my question

This is not doing what you expect from it:

aes.set_key(key, sizeof(key));

since sizeof(byte*) will return 2 or 4 (depending on the device you are using) and not the length of the string - try:

aes.set_key(key, strlen((char*)key));

im using a wemos d1 r1

StealthRT:
im using a wemos d1 r1

The default stack size for an ESP8266 is 4k so your big (automatic) arrays will happily cause that to overflow.

Why not start with the example sketch which comes with the library (if this is the one you are using) GitHub - spaniakos/AES: AES for microcontrollers (Arduino & Raspberry pi) and add to that slowly to include the base64 encoding you are experimenting with?