Hi all,

I am too new to this library and i am trying to do encrypt and decrypt in
RSA. But it gives a error in decrypting.
This is my code

#include <stdio.h>
#include <string.h>
#include <openssl/rsa.h>
#include <openssl/engine.h>
#include <openssl/err.h>

main(){

ERR_load_RSA_strings();

    ERR_load_crypto_strings();

    RSA *rsa = RSA_generate_key(1024, 3, NULL, NULL);

    unsigned char *from = (char *)malloc(1024);
    unsigned char *to = (char *)malloc(1024);
    unsigned char *from2 = (char *)malloc(1024);

    RAND_bytes(from, 32);

    int i = RSA_public_encrypt(strlen(from), from, to, rsa,
RSA_PKCS1_OAEP_PADDING);
    printf("%d\n", i);

    i = RSA_private_decrypt(sizeof(to), to, from2, rsa,
RSA_PKCS1_OAEP_PADDING);
    printf("%i\n",i);

    printf("%s\n", ERR_error_string(ERR_get_error(), NULL));

}

This is the error it produces

128
-1
error:0407A079:rsa routines:RSA_padding_check_PKCS1_OAEP:oaep decoding error

can anyone help me on this

Thank You.

Reply via email to