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;
}