【发布时间】:2014-02-07 09:40:47
【问题描述】:
我已经安装了 OpenSSL 。我只想使用 OpenSSL 运行一个程序。
这是我的程序,取自 here 。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "openssl/aes.h"
int main(int argc, char* argv[])
{
AES_KEY aesKey_;
unsigned char userKey_[16];
unsigned char in_[16];
unsigned char out_[16];
strcpy(userKey_,"0123456789123456");
strcpy(in_,"0123456789123456");
fprintf(stdout,"Original message: %s", in_);
AES_set_encrypt_key(userKey_, 128, &aesKey_);
AES_encrypt(in_, out_, &aesKey_);
AES_set_decrypt_key(userKey_, 128, &aesKey_);
AES_decrypt(out_, in_,&aesKey_);
fprintf(stdout,"Recovered Original message: %s", in_);
return 0;
}
在编译程序时,我收到了与那里相同的错误消息,但那里提供的解决方案对我不起作用。
我仍然收到编译错误。
$ gcc -I/home/bholanath/Sources/openssl-1.0.1e/include/ op.c -lcrypt
/tmp/ccvHr9Jr.o: In function `main':
op.c:(.text+0x9c): undefined reference to `AES_set_encrypt_key'
op.c:(.text+0xbc): undefined reference to `AES_encrypt'
op.c:(.text+0xd7): undefined reference to `AES_set_decrypt_key'
op.c:(.text+0xf7): undefined reference to `AES_decrypt'
collect2: error: ld returned 1 exit status
$ gcc op.c -lcrypt
/tmp/ccDEZMog.o: In function `main':
op.c:(.text+0x9c): undefined reference to `AES_set_encrypt_key'
op.c:(.text+0xbc): undefined reference to `AES_encrypt'
op.c:(.text+0xd7): undefined reference to `AES_set_decrypt_key'
op.c:(.text+0xf7): undefined reference to `AES_decrypt'
collect2: error: ld returned 1 exit status
消除编译错误和运行我的程序的任何帮助都会很棒。 我在 Fedora linux 下使用 GCC。
【问题讨论】:
-
库路径中有
libcrypt.so吗?请注意,通常情况下,您应该使用-lssl和-lcrypto(而不是-lcrypt)。 -
谢谢菲利普。使用 -lcrypto 它正在工作。
-
你应该不使用
AES_encrypt和朋友。您应该使用EVP_*函数。请参阅 OpenSSL wiki 上的 EVP Symmetric Encryption and Decryption。事实上,您可能应该使用经过身份验证的加密,因为它提供 机密性和真实性。请参阅 OpenSSL wiki 上的 EVP Authenticated Encryption and Decryption。