I need to add AES encryption functionality to my C++ project. So far I am trying to write a wrapper class for Code project: C++ Implementation of AES++ which is to have the following functions:
- char* Encrypt(string& InputData); //takes plain text and returns encrypted data
- char* Decrypt(string& InputData); //takes encrypted data and returns plain text
But when I test my code only the first 32 bytes of the data are encrypted and decrypted.
The final line of the output is:-
This is Encryption Test My name
What is making it miss the rest of the string? What am I missing?
#include "Rijndael.h"
#include <iostream>
#include <string>
using namespace std;
string LenMod(string Input);
char* Encrypt(string& InputData)
{
    try
    {
        InputData = LenMod(InputData);
        char* OutputData = (char*)malloc(InputData.size() + 1); 
        memset(OutputData, 0, sizeof(OutputData));
        CRijndael AESEncrypter;
        AESEncrypter.MakeKey("HiLCoE School of Computer Science and Technology",CRijndael::sm_chain0, 16 , 16);
        AESEncrypter.Encrypt(InputData.c_str(), OutputData, sizeof(InputData), CRijndael::ECB);
        return OutputData;
    }
    catch(exception e)
    {
        cout<<e.what();
        return NULL;
    }
}
char* Decrypt(string& Input)
{
    try
    {
        Input = LenMod(Input);
        char* Output = (char*)malloc(Input.size() + 1); 
        memset(Output, 0, sizeof(Output));
        CRijndael AESDecrypter;
        AESDecrypter.MakeKey("HiLCoE School of Computer Science and Technology",CRijndael::sm_chain0, 16, 16);
        AESDecrypter.Decrypt(Input.c_str(), Output, sizeof(Input), CRijndael::ECB); 
        return Output;
    }
    catch(exception e)
    {
        cout<<e.what();
        return NULL;
    }
}
string LenMod(string Input)
{
    while(Input.length() % 16 != 0)
        Input += '\0';
    return Input;
}
int main()
{
    string s = "This is Encryption Test My name is yohannes tamru i am a computer science student";
    //cout<<LengthMod(s)<<endl;
    string temp1(Encrypt(s));
    string temp2(Decrypt(temp1));
    cout<<temp1<<endl<<endl<<temp2<<endl;
    system("pause");
return 0;
}
