1//
2// md5.cpp
3//
4// This sample demonstrates the DigestEngine, DigestOutputStream and
5// MD5Engine classes.
6//
7// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
8// and Contributors.
9//
10// SPDX-License-Identifier: BSL-1.0
11//
12
13
14#include "Poco/MD5Engine.h"
15#include "Poco/DigestStream.h"
16#include "Poco/StreamCopier.h"
17#include <fstream>
18#include <iostream>
19
20
21using Poco::DigestEngine;
22using Poco::MD5Engine;
23using Poco::DigestOutputStream;
24using Poco::StreamCopier;
25
26
27int main(int argc, char** argv)
28{
29 if (argc != 2)
30 {
31 std::cout << "usage: " << argv[0] << ": <input_file>" << std::endl
32 << " create the MD5 digest for <input_file>" << std::endl;
33 return 1;
34 }
35
36 std::ifstream istr(argv[1], std::ios::binary);
37 if (!istr)
38 {
39 std::cerr << "cannot open input file: " << argv[1] << std::endl;
40 return 2;
41 }
42
43 MD5Engine md5;
44 DigestOutputStream dos(md5);
45
46 StreamCopier::copyStream(istr, dos);
47 dos.close();
48
49 std::cout << DigestEngine::digestToHex(md5.digest()) << std::endl;
50
51 return 0;
52}
53