#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
// 提供密码的回调函数
static int pem_password_callback(char *buf, int size, int rwflag, void *password) {
const char *passwd = (const char *)password;
if (passwd == NULL) return 0; // 无密码情况
int len = strlen(passwd);
if (len >= size) {
return 0; // 密码太长,无法放入缓冲区
}
strcpy(buf, passwd);
return len;
}
void encryptAndDecrypt(const char *input_text, EVP_PKEY *public_key, EVP_PKEY *private_key) {
// 加密操作
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(public_key, NULL);
if (ctx == NULL) {
fprintf(stderr, "Error creating encryption context\n");
return;
}
// 计算加密所需空间
size_t