【发布时间】:2018-03-02 12:36:26
【问题描述】:
我正在尝试使用 RSA_public_encrypt 加密数据,但它似乎不起作用(retEnc 始终为 -1)。我还尝试使用ERR_get_error 和ERR_error_string 查找有关错误的更多信息。
这是代码:
RSA *rsaPkey = NULL;
FILE *pemFile;
fopen_s(&pemFile, filename.c_str(), "r");
rsaPkey = PEM_read_RSA_PUBKEY(pemFile, &rsaPkey, NULL, NULL);
fclose(pemFile);
if(rsaPkey == NULL)
throw "Error pubkey file";
int size = RSA_size(rsaPkey);
unsigned char *encrypted;
encrypted = new unsigned char[size];
string instr = "test";
int length = instr.length();
unsigned char *in = (unsigned char *)(instr.c_str());
unsigned long errorTrack = ERR_get_error() ;
int retEnc = RSA_public_encrypt(length, in, (unsigned char *)encrypted, rsaPkey, RSA_NO_PADDING);
errorTrack = ERR_get_error() ;
char *errorChar = new char[120];
errorChar = ERR_error_string(errorTrack, errorChar);
ERR_error_string 给我error:0406B07A:lib(4):func(107):reason(122)
我怎样才能找到有关此的更多详细信息,我在哪里可以找到库 4 和函数 107?
当我尝试使用 openssl cli 和相同的公钥文件进行加密时,加密工作正常。
【问题讨论】:
-
您可能还对 OpenSSL wiki 上的 Library Initialization 感兴趣。
标签: c++ openssl error-code