19void Sha1(
const String& payload_str, uint8_t *hash_output) {
20 const char *payload = payload_str.c_str();
24 mbedtls_md_context_t ctx;
25 mbedtls_md_type_t md_type = MBEDTLS_MD_SHA1;
27 const size_t payload_length = payload_str.length();
29 mbedtls_md_init(&ctx);
30 mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(md_type), 0);
31 mbedtls_md_starts(&ctx);
32 mbedtls_md_update(&ctx,
reinterpret_cast<const unsigned char *
>(payload),
34 mbedtls_md_finish(&ctx, hash_output);
35 mbedtls_md_free(&ctx);
45String
MD5(
const String& payload_str) {
46 const char *payload = payload_str.c_str();
47 char output[33] = {0};
49 const size_t payload_length = payload_str.length();
51 mbedtls_md5_context ctx_;
53 uint8_t buf_[16] = {0};
54 mbedtls_md5_init(&ctx_);
55#if ESP_ARDUINO_VERSION_MAJOR > 2
56 mbedtls_md5_starts(&ctx_);
57 mbedtls_md5_update(&ctx_, (
const uint8_t *)payload, payload_length);
58 mbedtls_md5_finish(&ctx_, buf_);
60 mbedtls_md5_starts_ret(&ctx_);
61 mbedtls_md5_update_ret(&ctx_, (
const uint8_t *)payload, payload_length);
62 mbedtls_md5_finish_ret(&ctx_, buf_);
64 mbedtls_md5_free(&ctx_);
65 for (i = 0; i < 16; i++) {
66 sprintf(output + (i * 2),
"%02x", buf_[i]);
68 return String(output);