Hy. I have to make a program to crypt a text entered from the keyboard whith aes 256 , but i have problems when i try to split the text in two.I get a bad_ptr when i declare
unsigned char** intext=new unsigned char* [16];
#include<iostream>
#include <fstream>
#include<conio.h>
#include <string>
#include "aes.h"
using namespace std;
int main(int argc, char **argv)
{
unsigned char key32[32];
unsigned char iv[16];
unsigned char* inbuf=new unsigned char[128];
unsigned char** intext=new unsigned char* [16];
unsigned char outbuf[128];
//memset(inbuf, 0, sizeof(inbuf));
cout<<"enter text:";
cin>>inbuf;
int lenght=strlen(reinterpret_cast<char*>(inbuf));
ifstream keyfile("file.key");
if(keyfile.is_open())
{
keyfile>>key32;
cout<<key32<<endl;
}
ifstream ivfile("file.iv");
if(ivfile.is_open())
{
ivfile>>iv;
cout<<iv<<endl;
}
ofstream criptfile("file.out");
memset(outbuf, 0, sizeof(outbuf));
AES_KEY aeskey;
AES_set_encrypt_key(key32, 32*8, &aeskey);
const int n=lenght/16+1;
cout<<lenght<<endl;
cout<<n<<endl;
int rest=lenght%16;
cout<<rest;
int l=0;
int m=0;
for(int j=0;j<lenght;j++)
{
intext[l][m]=inbuf[j];
m++;
if(m==16)
{
m=0;
l++;
}
}
AES_cbc_encrypt(inbuf, outbuf, 16, &aeskey, iv, AES_ENCRYPT);
if(criptfile.is_open())
{
criptfile<<outbuf;
cout<<outbuf;
}
getch();
}