17void Sha1(
const String& payload_str, uint8_t *hash_output) {
18 const char *payload = payload_str.c_str();
22 mbedtls_md_context_t ctx;
23 mbedtls_md_type_t md_type = MBEDTLS_MD_SHA1;
25 const size_t payload_length = payload_str.length();
27 mbedtls_md_init(&ctx);
28 mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(md_type), 0);
29 mbedtls_md_starts(&ctx);
30 mbedtls_md_update(&ctx,
reinterpret_cast<const unsigned char *
>(payload),
32 mbedtls_md_finish(&ctx, hash_output);
33 mbedtls_md_free(&ctx);
43String
MD5(
const String& payload_str) {
44 const char *payload = payload_str.c_str();
45 char output[33] = {0};
47 const size_t payload_length = payload_str.length();
49 mbedtls_md5_context ctx_;
51 uint8_t buf_[16] = {0};
52 mbedtls_md5_init(&ctx_);
53 mbedtls_md5_starts_ret(&ctx_);
54 mbedtls_md5_update_ret(&ctx_, (
const uint8_t *)payload, payload_length);
55 mbedtls_md5_finish_ret(&ctx_, buf_);
56 mbedtls_md5_free(&ctx_);
57 for (i = 0; i < 16; i++) {
58 sprintf(output + (i * 2),
"%02x", buf_[i]);
60 return String(output);