Crash while Encrypt Aes

02/28/2011 16:10 Lazeboy#1
Hi,
i think the problem is that i use strcat und malloc but what exactly the problem is i dont know.....

Code:
// Aes Encrypt.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Rijndael.h"
#include <fstream>
#include <iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	CRijndael Rij;
	char DecryptStr[16] = {0};
	char DecryptedStr[20] = {0};
	char filestr[999999] = {0};
	Rij.MakeKey("123456789",CRijndael::sm_chain0, 16,16);

	FILE *filein;
	filein = fopen(argv[1],"rb");
	fseek(filein,0,SEEK_END);
	int size = ftell(filein);
	rewind (filein);
	fseek(filein,0,SEEK_SET);
	char *bufin = (char*)malloc(sizeof(char)*size+1);
	memset(bufin,0,sizeof(char)*size);
	fread(bufin,1,size,filein);

	FILE *fileout;
	char outputname[999] = {0};
	sprintf(outputname,"%s.set",argv[1]);
	fileout = fopen(outputname,"a+");

	//für ft
	
	char bla[9999999] = {0};
  	for(int i = 0;i < (size);i+=16)
  	{
  		Rij.Encrypt(bufin+i, filestr,16);
  		strcat(bla,filestr);
 	}
	for(int i = 0;i < (size);i++)
	{
		bla[i+1] = bla[i];
	}
 	bla[0] = 0x0b;
 	fwrite(bla,1,(size+1),fileout);
	fclose(filein);
	fclose(fileout);
	free(bufin);
	cout << "fertig";
	cin.get();
	return 0;
}