I am trying to use OpenSSL for an AES encryption/decryption. The code looks as follows:
// Buffers
unsigned char encryptedbuffer[1024];
unsigned char outbuffer[1024];
unsigned char key[128/8];
memset(key, 0, sizeof(key));
AES_KEY enc;
AES_KEY dec;
AES_set_encrypt_key(key, 128, &enc);
AES_set_decrypt_key(key, 128, &dec);
unsigned char text[] = "Hello World";
cout << text << endl;
AES_encrypt(text,encryptedbuffer,&enc);
AES_decrypt(encryptedbuffer,outbuffer,&dec);
cout << outbuffer << endl;
On compilation the program crashes, giving only a windows message that the program stopt working. So far I have found out that it happens on the call of AES_set_encrypt_key(key, 128, &enc);
Any ideas what I am doing wrong?
I am using eclipse (MinGW) on windows and have installed OpenSSL 1.0.1i.
EDIT: I linked the OpenSSL lib to Eclips by going to
Project >> Properties >> C/C++ Build >> Settings
- Under
MinGW C++ Linker
toLibraries
- Under
Libraries (-l)
I includetlibeay32
andssleay32
- Under
Library search path (-L)
I put my path to the OpenSSL lib file (C:\OpenSSL-Win64\lib
)
I have already seen in other forums that a lot of suggestions mentioned the libs ssl and crypto. These however are not part of my OpenSSL instalation (Windows).