-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcryptopp_hash_algorithm.cpp
More file actions
50 lines (45 loc) · 1.08 KB
/
Copy pathcryptopp_hash_algorithm.cpp
File metadata and controls
50 lines (45 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "cryptopp_hash_algorithm.h"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4251 4275 4101)
#include "cryptopp_dll_init.h"
#endif
std::string CalcStringSHA256(const std::string &raw_data)
{
std::string hash;
try
{
CryptoPP::SHA256 sha256;
CryptoPP::StringSource(raw_data, true
, new CryptoPP::HashFilter(sha256
,new CryptoPP::HexEncoder(new CryptoPP::StringSink(hash))
)
);
}
catch(...)
{
hash.clear();
}
return hash;
}
std::string CalcFileSHA256(const std::string &filepath)
{
std::string hash;
try
{
CryptoPP::SHA256 sha256;
CryptoPP::FileSource(filepath.c_str(), true
, new CryptoPP::HashFilter(sha256
,new CryptoPP::HexEncoder(new CryptoPP::StringSink(hash))
)
);
}
catch(...)
{
hash.clear();
}
return hash;
}
#ifdef _MSC_VER
#pragma warning( pop )
#endif