forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd5.cpp
More file actions
executable file
·54 lines (43 loc) · 1.07 KB
/
md5.cpp
File metadata and controls
executable file
·54 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
51
52
53
54
//
// md5.cpp
//
// $Id: //poco/1.4/Foundation/samples/md5/src/md5.cpp#1 $
//
// This sample demonstrates the DigestEngine, DigestOutputStream and
// MD5Engine classes.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/MD5Engine.h"
#include "Poco/DigestStream.h"
#include "Poco/StreamCopier.h"
#include <fstream>
#include <iostream>
using Poco::DigestEngine;
using Poco::MD5Engine;
using Poco::DigestOutputStream;
using Poco::StreamCopier;
int main(int argc, char** argv)
{
if (argc != 2)
{
std::cout << "usage: " << argv[0] << ": <input_file>" << std::endl
<< " create the MD5 digest for <input_file>" << std::endl;
return 1;
}
std::ifstream istr(argv[1], std::ios::binary);
if (!istr)
{
std::cerr << "cannot open input file: " << argv[1] << std::endl;
return 2;
}
MD5Engine md5;
DigestOutputStream dos(md5);
StreamCopier::copyStream(istr, dos);
dos.close();
std::cout << DigestEngine::digestToHex(md5.digest()) << std::endl;
return 0;
}