forked from taganaka/SpeedTest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
83 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Created by Francesco Laurita on 6/3/16. | ||
// | ||
|
||
#include <sstream> | ||
#include "MD5Util.h" | ||
|
||
std::string MD5Util::hexDigest(const std::string &str) { | ||
unsigned char digest[MD5_DIGEST_LENGTH]; | ||
|
||
MD5_CTX ctx; | ||
MD5_Init(&ctx); | ||
MD5_Update(&ctx, str.c_str(), str.size()); | ||
MD5_Final(digest, &ctx); | ||
|
||
char hexDigest[33] = {'\0'}; | ||
for (int i = 0; i < 16; i++) | ||
std::sprintf(&hexDigest[i*2], "%02x", (unsigned int)digest[i]); | ||
|
||
return std::string(hexDigest); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Created by Francesco Laurita on 6/3/16. | ||
// | ||
|
||
#ifndef SPEEDTEST_MD5UTIL_H | ||
#define SPEEDTEST_MD5UTIL_H | ||
#if defined(__APPLE__) | ||
# define COMMON_DIGEST_FOR_OPENSSL | ||
# include <CommonCrypto/CommonDigest.h> | ||
#include <string> | ||
|
||
# define SHA1 CC_SHA1 | ||
#else | ||
# include <openssl/md5.h> | ||
#endif | ||
|
||
class MD5Util { | ||
public: | ||
static std::string hexDigest(const std::string &str); | ||
}; | ||
|
||
|
||
#endif //SPEEDTEST_MD5UTIL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters