如何解决OpenSSL LNK2019 错误
我正在尝试将 OpenSSL 与我在 Visual Studio 2019 中的 C++ 项目链接。我收到以下错误:
Error LNK2019 unresolved external symbol _EVP_EncryptUpdate referenced in function _main Crypter2 C:\Users\jcava\source\repos\Crypter2\Crypter2\encryption.obj 1
Error LNK2019 unresolved external symbol _ERR_print_errors_fp referenced in function _handleErrors Crypter2 C:\Users\jcava\source\repos\Crypter2\Crypter2\encryption.obj 1
Error LNK2019 unresolved external symbol _EVP_aes_128_cbc referenced in function _main Crypter2 C:\Users\jcava\source\repos\Crypter2\Crypter2\encryption.obj 1
Error LNK2019 unresolved external symbol _EVP_CIPHER_CTX_new referenced in function _main Crypter2 C:\Users\jcava\source\repos\Crypter2\Crypter2\encryption.obj 1
Error LNK2019 unresolved external symbol _EVP_CIPHER_CTX_reset referenced in function _main Crypter2 C:\Users\jcava\source\repos\Crypter2\Crypter2\encryption.obj 1
Error LNK2019 unresolved external symbol _EVP_Decryptinit_ex referenced in function _main Crypter2 C:\Users\jcava\source\repos\Crypter2\Crypter2\encryption.obj 1
Error LNK2019 unresolved external symbol _EVP_DecryptUpdate referenced in function _main Crypter2 C:\Users\jcava\source\repos\Crypter2\Crypter2\encryption.obj 1
Error LNK2019 unresolved external symbol _EVP_EncryptFinal_ex referenced in function _main Crypter2 C:\Users\jcava\source\repos\Crypter2\Crypter2\encryption.obj 1
Error LNK2019 unresolved external symbol _EVP_Encryptinit_ex referenced in function _main Crypter2 C:\Users\jcava\source\repos\Crypter2\Crypter2\encryption.obj 1
在VC++目录下我在include下添加:
"C:\Program Files (x86)\OpenSSL\include";
我在库目录下添加:
"C:\Program Files (x86)\OpenSSL\lib";
"C:\Program Files (x86)\OpenSSL\lib";
我的完整源代码是:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/conf.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/aes.h>
#include <winsock2.h>
#include <windows.h>
#pragma comment(lib,"ws2_32.lib")
#pragma comment(lib,"crypt32.lib")
#pragma comment(lib,"user32.lib")
#pragma comment(lib,"advapi32.lib")
void handleErrors(void){
ERR_print_errors_fp(stderr);
abort();
}
int main(){
//read in the exe file and convert its bytes to a string
FILE *inFile;
inFile = fopen("Quasar.exe","rb");
if (inFile == NULL){
perror("Failed to read in file\n");
}
printf("File read in complete!\n");
if(fseek(inFile,SEEK_END) == -1){
perror("Offset error\n");
};
unsigned long lSize = ftell(inFile);
if (lSize == -1){
perror("Size error\n");
}
rewind(inFile);
unsigned char *unencryptedText = (unsigned char*) malloc (sizeof(unsigned char)*lSize);
if (unencryptedText != NULL) {
fread(unencryptedText,1,lSize,inFile);
}
else {
printf("File error");
exit(0);
}
fclose(inFile);
unsigned char *encryptedText = (unsigned char*) malloc (3 *(sizeof(unsigned char)*lSize));
//encrypt these bytes with open ssl
printf("Encrypting...\n");
int outlen,tmplen;
unsigned char key[] = {0,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
unsigned char iv[] = {1,8};
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
EVP_CIPHER_CTX_init(ctx);
EVP_Encryptinit_ex(ctx,EVP_aes_128_cbc(),NULL,key,iv);
if(EVP_EncryptUpdate(ctx,encryptedText,&outlen,unencryptedText,lSize *sizeof(char)) == 0){
ERR_print_errors_fp(stderr);
return 0;
}
if(EVP_EncryptFinal_ex(ctx,encryptedText + outlen,&tmplen) == 0){
ERR_print_errors_fp (stderr);
return 0;
}
outlen += tmplen;
EVP_CIPHER_CTX_cleanup(ctx);
printf("Encrypt Success!\n");
char absPath[500];
strcpy (absPath,"encrypted.dat");
FILE *outFile = fopen(absPath,"wb");
if (encryptedText != NULL) {
fwrite(encryptedText,outFile);
}
else {
perror("File is null");
}
fclose (outFile);
//decrypt the files
unsigned char *decryptedText = (unsigned char*) malloc (sizeof(unsigned char)*lSize);
EVP_Decryptinit_ex(ctx,iv);
if(EVP_DecryptUpdate(ctx,decryptedText,lSize) == 0){
ERR_print_errors_fp (stderr);
return 0;
}
EVP_CIPHER_CTX_cleanup(ctx);
printf("Decrypt Success!\n");
return 0;
}
我在这里做错了什么?提前致谢!!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。