Topic: wc_DerToPem not found

Hi, I'm working on a project with an ESP32 programmed using Arduino IDE; I am currently writing the code to decrypt an encrypted MQTT message that has been encrypted in a C# enviroment (NET MAUI) using my private RSA key, but I'm having trouble fixing these errors.

I am having an Issue with the wc_DerToPem method, which I need to make a POST request to upload my public key to the database. The error I get is:

error: 'wc_DerToPem' was not declared in this scope

But I looked it up and it is declared in wolfssl / wolfcrypt / asn_public, which of course I'm including.
Everything works fine without decryption; due to privacy reasons I'll avoid to use the true addresses, usernames and passwords.

P.S.: if you notice something wrong with my code other than the reason I'm writing, feel free to suggest improvement, tips or other ways to asjust it.

Thanks in advance!

Header:

#ifndef CRYPTOGRAPHYTOOLS_H
#define CRYPTOGRAPHYTOOLS_H

#include <mbedtls/base64.h>
#include <wolfssl.h>
#include <wolfssl/options.h>
#include <wolfssl/wolfcrypt/aes.h>
#include <wolfssl/wolfcrypt/rsa.h>
#include <wolfssl/wolfcrypt/sha256.h>
#include <wolfssl/wolfcrypt/asn_public.h>
#include <ArduinoJson.h>
#include <HTTPClient.h>
#include <cstring>
#include <vector>
#include <string>

#define KEY_DIMENSION 2048
#define KEY_SIZE KEY_DIMENSION/8
#define EXPONENT 65537

class CryptographyTools {

  public:
    byte privDer[KEY_SIZE];
    byte pubDer[KEY_SIZE];
    word32 privSz, pubSz;

    int generateRsaKeypair(const char* DEVICE_ID, String API_ADDRESS);
    int rsaDecrypt(const byte* encrypted, int encryptedLen, byte* decrypted, int decryptedLen, RsaKey* rsaKey);
    //int aesDecrypt(const byte* encrypted, int encryptedLen, byte* decrypted, const byte* key, const byte* iv);
    int totalDecrypt(String json_message, std::string &decrypted_message, String API_ADDRESS);

};

#endif //CRYPTOGRAPHYTOOLS_H

Source:

#include <CryptographyTools.h>


int CryptographyTools::generateRsaKeypair(const char* DEVICE_ID, String API_ADDRESS) {
  
  ...
  byte pem[2048];
  int pemSz = wc_DerToPem(pubDer, pubSz, pem, sizeof(pem), PUBLICKEY_TYPE);
  if (pemSz < 0) {
    Serial.println("Error while converting from DER to PEM pubKey");
  }
  ...

  Serial.println("generate_rsa_keypair OK");
  return 0;
}

Share

Re: wc_DerToPem not found

Hi vainn48

Welcome to the wolfSSL forums. Try switching the includes so that the options.h comes before any other wolfSSL headers.

#include <wolfssl.h>
#include <wolfssl/options.h>

Is this for a personal project?

Thanks,
Eric - wolfSSL Support

Re: wc_DerToPem not found

Also, be sure that `WOLFSSL_DER_TO_PEM` is defined using a CFLAG when configuring wolfSSL:

./configure CFLAGS="-DWOLFSSL_DER_TO_PEM"

Re: wc_DerToPem not found

Hi, thank you for the include tip embhorn! Kind of, it's for a university project.

Also, regarding your second reply, what do you mean with configuring wolfSSL?
I'm sure this is a newbie and dumb question to ask, but I genuinely thought you just needed to include the library for the algorithms and you had everything going, but apparently I'm missing something.
What do you need to configure?

Thanks a lot again.

Share

Re: wc_DerToPem not found

I've been searching it up for a bit, and I've tried various methods:

None of the four versions avaible from the Arduino IDE had the configure file (I even searched it in the subfolders).
I've also tried installing with git clone (btw I'm from Windows) and it had a configure.ac file in the root, but with ./configure .ac CFLAGS="-DWOLFSSL_DER_TO_PEM" it prompted me with an error that seemed to be because it wasn't meant to be executed with ./ .
I also included settings.h.

Finally, if I try to include wolfssl/options.h before any other wolfssl header (even before wolfssl.h) I get a "No such file or directory" error on wolfssl/options.h.

Share

Re: wc_DerToPem not found

So if you are not using the autotools configure command, then you should be configuring with a file called user_settings.h and passing WOLFSSL_USER_SETTINGS to the project building wolfSSL. In this case there will not be an options.h file used.