我试图在将私钥和公钥存储在字符向量上的同时加密和解密消息。我已经尝试过 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)