gpt4 book ai didi

c++ - 错误 :0906D06C:PEM routines:PEM_read_bio:no start

转载 作者:行者123 更新时间:2023-12-02 10:08:29 25 4
gpt4 key购买 nike

得到这个非常烦人的错误。 error:0906D06C:PEM routines:PEM_read_bio:no start
代码:

RSA* publickey = cWrapper.getPublicKey("C:/rsa-stuff/public.pem");
QByteArray plain = "The man in the black fled into the desert and the gunslinger followed...";
QByteArray encrypted = cWrapper.encryptRSA(publickey, plain);

在加密RSA()中:
const char* publicKeyStr = data.constData();
qDebug() << publicKeyStr;
BIO* bio = BIO_new_mem_buf((void*)publicKeyStr, -1);
BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
RSA* rsaPubKey = PEM_read_bio_RSAPublicKey(bio, NULL, NULL, NULL);
if(!rsaPubKey) {
qDebug() << "Could not load public key, " << ERR_error_string(ERR_get_error(), NULL); // error is here
}
BIO_free(bio);

这就是我读取文件的方式:
QByteArray data;
QFile file(filename);

if(!file.open(QFile::ReadOnly))
{
printf("Error reading file: %s\n", file.errorString());
return data;
}

data = file.readAll();
file.close();
return data;

当我打印出 publicKeyStr 时,看起来不错。这是启用了所有字符的 Notepad++ View :
public key in notepad++

有人知道我在做什么错吗? super 烦人的问题:(

首先不是 this问题,因为我没有得到信任的部分。无论如何,我确实尝试了所有“解决方案”,但都没有奏效,同样的错误。

最佳答案

您的 RSA 公钥是 SubjectPublicKeyInfo PEM 格式,但您正尝试使用 PEM_read_bio_RSAPublicKey 读取它它尝试读取 PKCS#1 格式的 PEM RSA key 。尝试使用 PEM_read_bio_RSA_PUBKEY反而。

https://www.openssl.org/docs/man1.1.0/crypto/PEM_read_bio_RSAPublicKey.html

关于c++ - 错误 :0906D06C:PEM routines:PEM_read_bio:no start,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49332235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com