I'm trying to get MD5 hash with mbedtls by this code:
const char* to_MD5(String str)
{
//str = {"network_alarm" : {"version" : "1.0.0", "state" : "on", "channel" : 1, "data" : "human" } }
#define MD5_MAX_LEN 16
mbedtls_md5_context ctx;
unsigned char digest[MD5_MAX_LEN];
mbedtls_md5_init(&ctx);
mbedtls_md5_starts_ret(&ctx);
size_t read;
mbedtls_md5_update(&ctx, (unsigned char*)str.c_str(), sizeof(str));
mbedtls_md5_finish(&ctx, digest);
// Create a string of the digest
static char digest_str[MD5_MAX_LEN * 2];
for (int i = 0; i < MD5_MAX_LEN; i++) {
sprintf(&digest_str[i * 2], "%02x", (unsigned int)digest[i]);
}
return (const char*)digest_str;
}
When I run this code, the value returned is c588952e152f23c2e2b96ee8eca10104 . But the value from another md5 site is f64381916a685b98f622780ebaf5278d .
Why could it be? And how can I receive "normal" md5 hash at mbedtls? Thx!