Created
March 12, 2022 10:33
-
-
Save VNovytskyi/1b03b9f8b128464777c9b8b19eb08caf to your computer and use it in GitHub Desktop.
Arduino ESP32 Parsing RSA public key in PEM format from string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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