Page 1 of 1

does there have an example for rsa_pkcs1_encrypt(.....) function?

Posted: Mon Mar 13, 2017 9:46 am
by wziy520
does there have an example for rsa_pkcs1_encrypt(.....) function?

Re: does there have an example for rsa_pkcs1_encrypt(.....) function?

Posted: Tue Oct 09, 2018 11:31 pm
by SombraRPK
Hi, i'm just looking for the same! Did you know something about that you can share? Thanks!

Re: does there have an example for rsa_pkcs1_encrypt(.....) function?

Posted: Wed Oct 10, 2018 2:42 am
by ESP_Angus
Hi,

We don't have a standalone example of this function in ESP-IDF, but mbedTLS has a range of example programs (designed for Linux) which use the mbedTLS APIs.

An RSA encryption sample is here:
https://github.com/espressif/mbedtls/bl ... ypt.c#L152

This code (main function) will not work as-is in ESP-IDF, but you could adapt the relevant parts without too much trouble.

Re: does there have an example for rsa_pkcs1_encrypt(.....) function?

Posted: Mon Oct 15, 2018 9:03 pm
by SombraRPK
Thank you, ESP_Angus! I find a couple of things trying to make this code work. I'd be so glad that you could help me.
The first one. I was reading the code and I see it use files, do you know if I can use files with the ESP32? Or do you have a recommendation to make it work? I think the best would be having the key in a char array, but i'm really lost on it.
The second. I'm trying to compile the code on Mac OS X High Sierra using gcc, but i have some problems with the linker, appearantly (i attach a screenshot). Do you think I need to try on Linux?

Thanks in advance!

Re: does there have an example for rsa_pkcs1_encrypt(.....) function?

Posted: Mon Oct 15, 2018 10:36 pm
by ESP_Angus
SombraRPK wrote:Thank you, ESP_Angus! I find a couple of things trying to make this code work. I'd be so glad that you could help me.
The first one. I was reading the code and I see it use files, do you know if I can use files with the ESP32? Or do you have a recommendation to make it work? I think the best would be having the key in a char array, but i'm really lost on it.
This is up to you. You could adapt the code in these files to use keys in arrays instead (refer to the mbedTLS docs for the functions to use), or you can continue to load from the filesystem (using one of the supported ESP32 embedded filesystems). It's really up to you.
SombraRPK wrote: The second. I'm trying to compile the code on Mac OS X High Sierra using gcc, but i have some problems with the linker, appearantly (i attach a screenshot). Do you think I need to try on Linux?
You need to build the mbedTLS library on macOS and then pass the required gcc options to link in this library. mbedTLS includes some Makefiles and CMakeLists files for the library and the example programs, which should help do this for you.

Unfortunately, supporting C programming on macOS is outside the scope of this forum - but there are lots of other resources online which can help you learn.

Re: does there have an example for rsa_pkcs1_encrypt(.....) function?

Posted: Mon Oct 15, 2018 10:55 pm
by SombraRPK
Thanks a lot. What would you recommend me, talking about the string-in key or file-in key? And about the mbedTLS docs, are these? https://tls.mbed.org/api/, or are there some others specifically for ESP?