【发布时间】:2021-10-17 14:14:33
【问题描述】:
我意识到我不能使用 OpenSSL 1.0.0 中的函数 RSA_get0_key 来提取 n, e, d 的值,方法是从文件中读取私钥并将其作为参数传递给上述功能。
这不是编程问题,我的意思是,我知道如何使用这些功能,但我不知道是否有替代方法。
确实,在编译操作期间阻止我的警告如下:
warning: implicit declaration of function ‘RSA_get0_key’; did you mean ‘RSA_check_key’? [-Wimplicit-function-declaration]
你知道怎么做吗?我在这里查看手册(https://www.openssl.org/docs/man1.0.2/man3/),但似乎没有适当的功能可以做到这一点。此外,我需要符合 OpenSSL 1.0.0。
代码
#include <stdio.h>
#include <stdlib.h>
#include <openssl/rsa.h>
#include <openssl/obj_mac.h>
#include <openssl/rand.h>
#include <openssl/bn.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/pem.h>
int main()
{
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
RSA *privkey = RSA_new();
FILE *privkeyfile = fopen("private.key", "rb");
PEM_read_RSAPrivateKey(privkeyfile, &privkey, NULL, NULL);
fclose(privkeyfile);
BIGNUM *n, *e, *d = NULL;
RSA_get0_key(privkey,&n,&e,&d);
return 0;
}
【问题讨论】:
-
向我们展示您的代码。
-
@RobertHarvey 问题已更新。
-
嗯,rsa.h 的第 217 行说此功能已弃用。
-
FWIW,在 OpenSSL