diff --git a/src/ESP32React/ArduinoJsonJWT.cpp b/src/ESP32React/ArduinoJsonJWT.cpp index 7e7676af5..bbc2b11ac 100644 --- a/src/ESP32React/ArduinoJsonJWT.cpp +++ b/src/ESP32React/ArduinoJsonJWT.cpp @@ -70,16 +70,12 @@ void ArduinoJsonJWT::parseJWT(String jwt, JsonDocument & jsonDocument) { */ String ArduinoJsonJWT::sign(String & payload) { std::array hmacResult{}; - { - mbedtls_md_context_t ctx; - mbedtls_md_type_t md_type = MBEDTLS_MD_SHA256; - mbedtls_md_init(&ctx); - mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(md_type), 1); - mbedtls_md_hmac_starts(&ctx, reinterpret_cast(_secret.c_str()), _secret.length()); - mbedtls_md_hmac_update(&ctx, reinterpret_cast(payload.c_str()), payload.length()); - mbedtls_md_hmac_finish(&ctx, hmacResult.data()); - mbedtls_md_free(&ctx); - } + mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), + reinterpret_cast(_secret.c_str()), + _secret.length(), + reinterpret_cast(payload.c_str()), + payload.length(), + hmacResult.data()); return encode(reinterpret_cast(hmacResult.data()), hmacResult.size()); }