diff options
author | eidheim <eidheim@gmail.com> | 2016-12-20 13:44:05 +0300 |
---|---|---|
committer | eidheim <eidheim@gmail.com> | 2016-12-20 13:45:52 +0300 |
commit | 7ce16e8e0aa8a7ddc887939dcccefa29e665b97c (patch) | |
tree | 754473125802db5133f19ef59168b08dff445931 /crypto.hpp | |
parent | b13ae3f997b6f9e2ae041efe7a1bb88eb581f012 (diff) |
Added Crypto::to_hex_string
Diffstat (limited to 'crypto.hpp')
-rw-r--r-- | crypto.hpp | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -3,6 +3,8 @@ #include <string> #include <cmath> +#include <sstream> +#include <iomanip> //Moving these to a seperate namespace for minimal global namespace cluttering does not work with clang++ #include <openssl/evp.h> @@ -75,6 +77,15 @@ namespace SimpleWeb { } }; + /// Return hex string from bytes in input string. + static std::string to_hex_string(const std::string &input) { + std::stringstream hex_stream; + hex_stream << std::hex << std::internal << std::setfill('0'); + for (auto &byte : input) + hex_stream << std::setw(2) << (int)(unsigned char)byte; + return hex_stream.str(); + } + static std::string MD5(const std::string &input, size_t iterations=1) { std::string hash; |