From: Thomas Jarosch Date: Mon, 8 Nov 2010 15:29:22 +0000 (+0100) Subject: Fix md5 to hex conversion: Output a leading zero for values smaller than ten X-Git-Tag: v1.1~32 X-Git-Url: http://developer.intra2net.com/git/?p=bpdyndnsd;a=commitdiff_plain;h=55d580e83d14469b0b49bc4f9d5c8a04ee70a053 Fix md5 to hex conversion: Output a leading zero for values smaller than ten --- diff --git a/src/util.cpp b/src/util.cpp index fe11814..6b7cbda 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -10,6 +10,7 @@ #include "util.hpp" #include +#include #include #include @@ -92,7 +93,8 @@ std::string compute_md5_digest(std::string data) { // We have to do a static cast to an decimal representation, cause otherwise ostringstream would interpret // the stream as a character and output the character representation of the hex value. - oss_digest_md5_hex << std::hex << static_cast(md_value[i]); + oss_digest_md5_hex << std::nouppercase << std::setw(2) << std::setfill('0') + << std::hex << static_cast(static_cast(md_value[i])); } return oss_digest_md5_hex.str();