Topic: RSA decryption failed, this is the code

WOLFSSL_RSA* ppri_key = NULL;
int nfLen = 128;
unsigned char uszDeData[1024] = {0};
ppri_key = wolfSSL_RSA_new();
ppri_key->e = wolfSSL_BN_bin2bn(PUBLIC_EXPONENT_HEX,3,NULL);
ppri_key->d = wolfSSL_BN_bin2bn(PRIVATE_EXPONENT_HEX,128,NULL);
ppri_key->n = wolfSSL_BN_bin2bn(MODULES_HEX,128,NULL);

int nRet = wolfSSL_RSA_private_decrypt(nfLen,upszEnData,uszDeData,ppri_key,RSA_PKCS1_PADDING);

It returns - 1,and uszDeData is empty.
How to use large number to construct private key to decrypt?Please give me an example. Thanks!
If the upszEnData length exceeds 2048,how to do it?

Share

Re: RSA decryption failed, this is the code

Hi juhuaguai,

I do not believe we have any examples showing the use of the WOLFSSL_RSA data structure being used in this way. One could use the internal RsaKey structure and possibly wc_RsaPublicKeyDecode to accomplish what you are attempting but let me check with the team tomorrow in a meeting and see if any of our other engineers have an example of using the WOLFSSL_RSA data structure in this way.

Warm Regards,

K

Re: RSA decryption failed, this is the code

juhuaguai,

I went over this with the team and unfortunately we don't have any examples lying around, can you send a short complete test app that can be compiled and run with the commands:

$ gcc test.c -o run-test -lwolfssl
$ ./run-test

Also note that you are only setting the e,d, and n, you're missing some elements of the private key also (p, q, dP, dQ, u).

Warm Regards,

K

Re: RSA decryption failed, this is the code

I have uploaded the test code to GitHub.https://github.com/juhuaguai/temptest
It is an MFC project of vs2019.
The code shows the encryption and decryption of OpenSSL and wolfssl respectively.
RSA of OpenSSL works normally.
Wolfssl can't decrypt normally, but its encrypted string can be decrypted by OpenSSL.
Please tell me how to modify the code.
Thank you very much.

Share

Re: RSA decryption failed, this is the code

juhuaguai,

Can you tell us a bit about the background of this project using .NET framework and solution setup?

Warm Regards,

K

Re: RSA decryption failed, this is the code

K,
This is a C + + Project and it didn't use c#,it doesn't need .Net framework。
Try it, you need to install Microsoft Visual Studio 2019, and choose C + + and MFC when installing.
Do you have any mistakes? Can you send an error message?
You can see the relevant code directly in the RsaTestDlg.cpp file.
thank you.
juhuaguai

Share

Re: RSA decryption failed, this is the code

Juhuaguai,

We would very much appreciate knowing if the project is commercial, open source, hobby, personal research etc to better classify the inquiry. Can you share a bit about the background of the project and what drove this work?

Thanks!

Warm Regards,

K

Re: RSA decryption failed, this is the code

K,
Don't worry. This is the temporary code I wrote during my personal research.
The private key and so on are generated temporarily, without any risk.
It doesn't involve any copyright and confidentiality.
It's just an example for testing. All the codes in it can be shared, disclosed and modified at will.
Thanks!
Juhuaguai

Share