Can any one help me out with the code below I dont understand properly what is the error problem in this . I'm using AES API's to decrypt. Here is my code : I need to decrypt a binary file...i only have key and iv and i was given the mode of encryption asked to decrypt the binary file..so this was procedure i followed..can any one correct me where is wrogong in my code... #include #inclide #incldue int main() {
unsigned long lSize; FILE * inFile; FILE * outFile; size_t n,m; char * pTemp; char * buffer; const AES_KEY *key; inFile = fopen("SB2.bin", "rb"); outFile = fopen("finalPackResult", "wb+"); unsigned char uKey[]= "3834373532303435333730323834383132373330393233343531323330383839"; unsigned char iv[] = "36363333383630393433313132323031"; int keyLength = sizeof(uKey); int ivLength = sizeof(iv); printf("key length:%d.\n",keyLength); printf("Initialisation vector length:%d.\n",ivLength); /* get file size and allocate memory to buffer */ fseek (inFile , 0,SEEK_END); lSize = ftell (inFile); rewind (inFile); printf("File size is: %ld.\n",lSize); unsigned char pInBuff[lSize]; unsigned char pOutBuff[lSize]; /* Allocate memory */ memset(pInBuff,0,lSize * sizeof(char)); memset(pOutBuff,0,lSize * sizeof(char)); buffer = (char *)malloc(sizeof(char)*lSize); /* Read the input signature package which contains * encrypted data. The AES encryption technique * with CBC mode is followed */ if ((n = fread (pInBuff, 1, lSize, inFile)) == -1) { printf ("read error"); return -1; } printf("Data read from input binary is :%d\n", n); if (n == 0) { printf ("Data read error from input file.\n"); return -1; } printf("LINE :%d.\n",__LINE__); /* The AES_cbc_encrypt() function implements the Cipher Block Chaining (CBC) * mode of operation. It encrypts or decrypts B<in> using the key schedule * B<schedule> and places the result in B<out>. The value of B<length> is * the length of B<in> in bytes */ AES_set_decrypt_key(uKey, 256, &key); printf("LINE :%d.\n",__LINE__); AES_cbc_encrypt(pInBuff, pOutBuff, lSize, key, iv, AES_DECRYPT);---here i'm getting segfault printf("LINE :%d.\n",__LINE__); pTemp = AES_options(); printf("AES function to which pointed:%s.\n", pTemp); /* Write decrypted data into a file */ if((m=fwrite(pOutBuff, 1, lSize, outFile)) == -1) { printf ("Write error.\n"); } if(m != n) { printf("Didn't write the data properly.%dbytes info missed",n-m); } printf("size of data written is:%d.\n",m); return 0; } Thanks in Advance. -- View this message in context: http://old.nabble.com/AES-cbc--How-to-Init-Openssl--tp12475822p26387613.html Sent from the OpenSSL - User mailing list archive at Nabble.com. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org