#include "util.hpp"
 
 #include <sstream>
+#include <iomanip>
 #include <openssl/evp.h>
 #include <boost/algorithm/string.hpp>
 
     {
         // 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<unsigned short>(md_value[i]);
+        oss_digest_md5_hex << std::nouppercase << std::setw(2) << std::setfill('0')
+                           << std::hex << static_cast<int>(static_cast<unsigned char>(md_value[i]));
     }
 
     return oss_digest_md5_hex.str();