小编sbu*_*wal的帖子

C++ openssl - 生成 RSA 密钥对并读取

我正在尝试使用 openssl 库生成 RSA 密钥对,然后稍后读取相同的密钥。但是,它失败了。有时它会给我这个错误:

错误:0906D06C:PEM 例程:PEM_read_bio:没有起始行

有时,它会给我这个错误:

错误:0906D06C:lib(9):func(109):reason(108)

生成密钥对并稍后能够读取它的正确方法是什么?这是我的代码。如果您运行它,您会发现它正确生成了 RSA 密钥对,但稍后无法读取它们。

    #include <stdio.h>
    #include <iostream>
    #include <openssl/rsa.h>
    #include <openssl/pem.h>
    #include <openssl/err.h>
    #include <exception>

    bool generate_key() {
        size_t pri_len;            // Length of private key
        size_t pub_len;            // Length of public key
        char *pri_key;           // Private key in PEM
        char *pub_key;           // Public key in PEM

        int ret = 0;
        RSA *r = NULL;
        BIGNUM *bne = NULL;
        BIO *bp_public = NULL, *bp_private = NULL;
        int bits = 2048;
        unsigned long …
Run Code Online (Sandbox Code Playgroud)

c++ openssl rsa key-pair

5
推荐指数
1
解决办法
8413
查看次数

标签 统计

c++ ×1

key-pair ×1

openssl ×1

rsa ×1