9 months ago.

MBEDTLS Inavlid padding

Hi, Currently I am trying to encrypt and decrypt a message using RSA. I am able to decrpyt a message encrypted with another tool, and I am able to encrypt something like "hello world" BUT I am not able to decrypt the data encrypted by my own program...

I always get err= -16640 -> RSA - Input data contains invalid padding and is rejected.

The Keypair I am using is definitly valid. any Ideas what I am doing wrong?

RSA test

    unsigned char output[1000];
    int err = mbedtls_pk_encrypt( pubK, (unsigned char*)"hallo123", 8,bbuf, &olen, sizeof(bbuf),mbedtls_ctr_drbg_random, ctr_drbg);  
    if(err!=0)
    {
        char buf[128];
        mbedtls_strerror(err,buf,sizeof(buf));
        logger.logInfo("rsa encryption failed, err= %i -> %s",err,buf);
        return;
    } 

    err = mbedtls_pk_decrypt(prvK, bbuf, olen, output, &olenR, sizeof(output), mbedtls_ctr_drbg_random, ctr_drbg);
    if (err != 0)
    {
        char buf[128];
        mbedtls_strerror(err, buf, sizeof(buf));
        logger.logInfo("rsa decryption failed, err= %i -> %s", err, buf);
        return;
    }

thanks, Jonas

Comment on this question
Be the first to answer this question.

You need to log in to post a question