From 3271f328de35f940f682a0dbe1d9466e29190182 Mon Sep 17 00:00:00 2001 From: Naios Date: Sun, 17 Apr 2016 19:30:13 +0200 Subject: Core/Cryptography: Move the SHA1 calculate helper to the SHA1 header --- src/common/Cryptography/SHA1.cpp | 8 ++++++++ src/common/Cryptography/SHA1.h | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/common') diff --git a/src/common/Cryptography/SHA1.cpp b/src/common/Cryptography/SHA1.cpp index a01bd7844ee..aed4a069827 100644 --- a/src/common/Cryptography/SHA1.cpp +++ b/src/common/Cryptography/SHA1.cpp @@ -18,6 +18,7 @@ #include "SHA1.h" #include "BigNumber.h" +#include "Util.h" #include #include @@ -67,3 +68,10 @@ void SHA1Hash::Finalize(void) SHA1_Final(mDigest, &mC); } +std::string CalculateSHA1Hash(std::string const& content) +{ + unsigned char digest[SHA_DIGEST_LENGTH]; + SHA1((unsigned char*)content.c_str(), content.length(), (unsigned char*)&digest); + + return ByteArrayToHexStr(digest, SHA_DIGEST_LENGTH); +} diff --git a/src/common/Cryptography/SHA1.h b/src/common/Cryptography/SHA1.h index 970ab5c0cb9..37ac2cc0166 100644 --- a/src/common/Cryptography/SHA1.h +++ b/src/common/Cryptography/SHA1.h @@ -46,5 +46,8 @@ class TC_COMMON_API SHA1Hash SHA_CTX mC; uint8 mDigest[SHA_DIGEST_LENGTH]; }; -#endif +/// Returns the SHA1 hash of the given content as hex string. +TC_COMMON_API std::string CalculateSHA1Hash(std::string const& content); + +#endif -- cgit v1.2.3