Topic: Unable to decrypt ciphertext using wc_RsaPrivateDecrypt
Anyone able to assist me in this matter? I'm not able to obtain the plaintext value after decrypting. I get the error "RNG required but not provided"
#include <stdio.h>
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/rsa.h>
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/error-crypt.h>int main(){
RsaKey priv;
WC_RNG rng;
int ret = 0;
byte out[256];
byte in[40] = "hello";
byte plain[40];
char errorString[80];long e = 65537; // standard value to use for exponent
wc_InitRsaKey(&priv, NULL); // not using heap hint. No custom memory
wc_InitRng(&rng);
// generate 2048 bit long private key
ret = wc_MakeRsaKey(&priv, 2048, e, &rng);
if( ret != 0 )
{
printf("key not generated!");
}ret = wc_RsaPublicEncrypt(in, sizeof(in), out, sizeof(out), &priv, &rng);
if ( ret < 0 )
{
printf("Encrypting message failed");
}printf("%s\n", out);
printf("hello world \n");
printf("%d", ret);ret = wc_RsaPrivateDecrypt(out, ret, plain, sizeof(plain), &priv);
// if (ret < 0)
// {
// return -1;
// }printf("\n%d\n", ret);
printf("\n%s\n", plain);return 0;
}