8th program RSA
8th program RSA
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void handle_errors(const char *msg) {
fprintf(stderr, "%s\n", msg);
ERR_print_errors_fp(stderr);
exit(1);
}
int main() {
// Step 1: Generate RSA Key Pair
int bits = 2048;
RSA *rsa = generate_rsa_keypair(bits);
// Step 2: Prepare the message to encrypt
const char *message = "Hello, RSA encryption!";
unsigned char encrypted[256]; // Buffer for encrypted message
unsigned char decrypted[256]; // Buffer for decrypted message
int encrypted_length, decrypted_length;
printf("Original message: %s\n", message);
// Step 3: Encrypt the message using the public key
// Clean up
RSA_free(rsa);
return 0;
}
OUTPUT
LIBRARIES: