小编ghy*_*ur7的帖子

如何从包含 OpenSSL 中的公钥的字符数组中获取 RSA* 对象?

我试图在将私钥和公钥存储在字符向量上的同时加密和解密消息。我已经尝试过 d2i_PublicKey(...) 并在 EVP_set1_RSA(...) 中使用 EVP_PKEY 对象。我也不知道 EVP_set1_RSA(...) 中的所有参数是什么。请帮忙。这是我的代码:

#include <stdio.h>

//RSA
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <arpa/inet.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/x509.h>

#define RSA_KEY_LENGTH 2048
#define PUB_EXP     3
#define PRINT_KEYS

//RSA


int main()
{
    printf("\ngenerating keys...\n");
    RSA *keypair = RSA_generate_key(RSA_KEY_LENGTH, PUB_EXP, NULL, NULL);


    // ---------

    printf("Converting Keys to char array..\n");

    char   *pri_key = NULL;           // Private key
    char   *pub_key = NULL;           // Public key
    size_t pri_len;            // Length of private key
    size_t pub_len;            // Length of …
Run Code Online (Sandbox Code Playgroud)

c++ encryption openssl rsa char

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

标签 统计

c++ ×1

char ×1

encryption ×1

openssl ×1

rsa ×1