LNK2019 error when compiling code
I have some sample code that I was editing in Visual Studio 2010 to encrypt and decrypt using DES. For some reason, when I compile the code i keep getting these two LNK2019 errors that are referring to the des_encrypt1() function and the des_set_key_checked() function. As seen in my code, I made sure to include the des.h file and that file lists the definitions for both of those functions. I am new to C so I am not sure if it is something simple that I am overlooking but any help would be greatly appreciated. I'm not sure how to correctly attach code here so sorry if the format looks weird but the bolded include below should say #include des.h.
#include <des.h>
#define ENC 1
#define DEC 0
//extern des_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);
//void des_set_key_checked(const_des_block *key, des_key_schedule *schedule)
int main()
{
int k;
long in[2];
sta开发者_JAVA百科tic unsigned char cbc_key[8] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
des_key_schedule key;
//struct timeval start, end;
//double t1, t2, t3, t4;
if ((k = des_set_key_checked(&cbc_key,key)) != 0)
printf("\nkey error\n");
in[0] = 3212314;
in[1] = 1231233;
printf("DES Clear Text: %ld%ld\n",in[0],in[1]);
//gettimeofday(&start, NULL);
//t1=start.tv_sec+(start.tv_usec/1000000.0);
des_encrypt1(in,key,ENC);
//gettimeofday(&end, NULL);
//t2=end.tv_sec+(end.tv_usec/1000000.0);
//printf("Time for Encryption\n", t2-t1);
printf("DES Encryption: %u%u\n",in[0],in[1]);
//gettimeofday(&start, NULL);
//t3=start.tv_sec+(start.tv_usec/1000000.0);
des_encrypt1(in,key,DEC);
//gettimeofday(&end, NULL);
//t4=end.tv_sec+(end.tv_usec/1000000.0);
//printf("Time for Decryption\n", t4-t3);
}
If you are compiling the code as C++, but the header is written for C, you need to include it as follows:
extern "C" {
#include "des.h"
}
you need to include des.h from openssl/
#include <openssl/des.h>
精彩评论