c - C 中的 OpenSSL 1.0.0 RSA 参数
问题描述
我意识到我无法使用OpenSSL 1.0.0RSA_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;
}
解决方案
该RSA_get0_key
函数作为抽象添加到 OpenSSL 1.1.0 中,用于检索 RSA 密钥的n
、e
和d
值。对于早期版本,您需要直接访问这些字段。
n = privkey->n;
e = privkey->e;
d = privkey->d;
如果您希望您的代码能够处理 1.0.x 和 1.1.x,您可以检查以下值OPENSSL_VERSION_NUMBER
:
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
RSA_get0_key(privkey, &n, &e, &d);
#else
n = privkey->n;
e = privkey->e;
d = privkey->d;
#endif
推荐阅读
- ffmpeg - 多个音频同时播放
- google-cloud-platform - 如何将 OAuth 2.0 用于服务器到服务器应用程序
- python - 如何修复 Python Pandas 图?
- javascript - StartTag:JSON 到 XML 转换时元素名称无效错误
- typescript - 在 TypeScript 中定义自定义类型时出现意外标识符
- nlp - pytorch 中的自注意力实现
- amazon-web-services - 适用于 CDN 和 API 的 AWS WAF
- python - 一旦我包含 BiLSTM 层,Tensorflow 模型的形状等级问题
- c# - 如何检查 Angular 项目中的 ASP.NET Web API 是否返回错误?
- python - GoogleAds 搜索流转 json