当我尝试编译以下代码时出现此错误。我安装了 openssl 库。我不懂编程。错误是: “ccS3fmrV.o:wa_pbkdf2.c:(.text+0x1e3):对‘PKCS5_PBKDF2_HMAC_SHA1’的 undefined reference collect2.exe:错误:ld 返回 1 退出状态
有人可以帮忙吗?谢谢。
#include <stdio.h>
#include <string.h>
#include <openssl/x509.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
int main(int argc, char *argv[])
{
unsigned char pass[1024]; // passphrase read from stdin
unsigned char salt[1024]; // salt
int salt_len; // salt length
int ic; // iteration
unsigned char result[1024]; // result
FILE *fp_salt;
if ( argc != 3 ) {
fprintf(stderr, "usage: %s salt_file iteration < passwd_file > binary_key_file \n", argv[0]);
exit(1);
}
ic = atoi(argv[2]);
fp_salt = fopen(argv[1], "r");
if(!fp_salt) {
fprintf(stderr, "error opening salt file: %s\n", argv[1]);
exit(2);
}
salt_len=0;
int ch;
while((ch = fgetc(fp_salt)) != EOF) {
salt[salt_len++] = (unsigned char)ch;
}
fclose(fp_salt);
fgets(pass, 1024, stdin);
if ( pass[strlen(pass)-1] == '\n' )
pass[strlen(pass)-1] = '\0';
PKCS5_PBKDF2_HMAC_SHA1(pass, strlen(pass), salt, salt_len, ic, 16, result);
fwrite(result, 1, 16, stdout);
return(0);
}
最佳答案
I get the error undefined reference to `PKCS5_PBKDF2_HMAC_SHA1'. How do I fix it?
PKCS5_PBKDF2_HMAC_SHA1
已在 1.0.0 (IIRC) 中添加。因此请确保您使用的是 OpenSSL 1.0.0 或更高版本。 PKCS5_PBKDF2_HMAC_SHA1 上有一个 OpenSSL 手册页。 ,但它的历史记录是空的。
如果您使用的是 OpenSSL 1.0.1,请确保为链接器包含 libcrypto
。您的编译/链接命令应类似于:
gcc wa_pbkdf2.c -o wa_pbkdf2.exe -lcrypto
关于c - 我收到错误 undefined reference to `PKCS5_PBKDF2_HMAC_SHA1' 。我如何解决它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27538343/