-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsha256.cpp
More file actions
50 lines (43 loc) 路 1.07 KB
/
Copy pathsha256.cpp
File metadata and controls
50 lines (43 loc) 路 1.07 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
50
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <crypto++/sha.h>
#include <crypto++/hex.h>
#include <crypto++/files.h>
using namespace CryptoPP;
int main(int argc, char *argv[])
{
if (argc != 3)
{
std::cout << "Usage: " << argv[0] << " <input_file> <output_file>" << std::endl;
return 1;
}
std::string input_file = argv[1];
std::string output_file = argv[2];
try
{
SHA256 hash;
std::string digest;
FileSource f(input_file.c_str(), true,
new HashFilter(hash,
new HexEncoder(new StringSink(digest), false)));
std::ofstream output(output_file);
if (output.is_open())
{
output << digest;
output.close();
}
else
{
std::cout << "Unable to open output file." << std::endl;
return 1;
}
}
catch (const Exception &ex)
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}