Skip to content

Instantly share code, notes, and snippets.

@VNovytskyi
Created March 12, 2022 10:33
Show Gist options
  • Save VNovytskyi/1b03b9f8b128464777c9b8b19eb08caf to your computer and use it in GitHub Desktop.
Save VNovytskyi/1b03b9f8b128464777c9b8b19eb08caf to your computer and use it in GitHub Desktop.
Arduino ESP32 Parsing RSA public key in PEM format from string
#include "mbedtls/pk.h"
#include "mbedtls/error.h"
mbedtls_pk_context pk;
const char* esp_pub_key_pem_test = "-----BEGIN PUBLIC KEY-----\n\
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXn7jOg8QBSKJNmN4FqWtXa/+9\n\
BbOpHdtN7k9ij95xQmLPV/DptPPKgM6mhK4k7va3ftD+Gv7LcmPELCPMqIvq2aLf\n\
tgAb80HyHorfk6zQfNcyyJ0fblpyVschCMtO3qD4wahLlUcECf7uyVRFBHPxVrwi\n\
UmK6TCiIjnSF2QahywIDAQAB\n\
-----END PUBLIC KEY-----";
void setup() {
mbedtls_pk_init(&pk);
size_t key_len = strlen(esp_pub_key_pem_test) + 1;
int res = mbedtls_pk_parse_public_key(&pk, (const uint8_t*)esp_pub_key_pem_test, key_len);
if (res != 0) {
char buff[512];
mbedtls_strerror(res, buff, sizeof(buff));
printf("Parse key error: %s\n", buff);
return;
}
printf("Parse key ok\n");
}
void loop() {
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment