Hi , I am new to this openssl libraries.
I am facing a issue in the below code. When I encrypt, it is giving all zeroes as output. And when I decrypt I am not getting the exact message. Please, I need help in this. #define BUFSIZE 1024 int main(int argc, char *argv[]) { int i; unsigned char out[BUFSIZE]={0}; unsigned char in[]={0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00}; for(i=0;i<8;i++) printf("%2X\n",in[i]); cryptWrapper(in, out); printf("Encrypted/Decrypted string is: [%s]\n", out); return 0; } int cryptWrapper(unsigned char *in, unsigned char *out) { unsigned char EncrOut[BUFSIZE]={0}; unsigned char DecrOut[BUFSIZE]={0}; int ret; unsigned char tdesKey1[8] ={0xEF,0x38,0xE0,0xE0,0x58,0xA7,0x08,0x8C}; unsigned char tdesKey2[8] ={0x51,0x01,0x37,0xFE,0xBC,0xE0,0x4C,0x85}; unsigned char initVector[8] ={0x38,0x37,0x36,0x35,0x34,0x33,0x32,0x31}; // The initializationvector int i; des_key_schedule kSched1, kSched2; des_cblock iv; memcpy(iv,initVector,sizeof(initVector)); // set the initialization vector ret=DES_set_key_checked(&tdesKey1, &kSched1); printf("ret %d\n",ret); // set the key schedule DES_set_key_checked(&tdesKey2, &kSched2); // set the key schedule // DES_set_key_checked(&tdesKey3, &kSched3); // set the key schedule for(i=0;i<8;i++) printf("%2X\n",in[i]); memset(out, 0, BUFSIZE); des_ede2_cbc_encrypt(in, EncrOut, (long)strlen((char*)in), kSched1,kSched2, &iv, DES_ENCRYPT); // Encrypt for(i=0;i<8;i++) printf("Encrypted %X\n",EncrOut[i]); memcpy(iv,initVector,sizeof(initVector)); DES_set_key_checked(&tdesKey1, &kSched1); DES_set_key_checked(&tdesKey2, &kSched2); // DES_set_key_checked(&tdesKey3, &kSched3); des_ede2_cbc_encrypt((unsigned char*)EncrOut, DecrOut,(long)strlen((char*)EncrOut), kSched1, kSched2, &iv,DES_DECRYPT); for(i=0;i<8;i++) printf("Decrypted %X\n",DecrOut[i]); strcpy((char *) out, (char *) DecrOut); return 0; } Regards, ChandraSekhar.