Samir Faci wrote:
I'm trying to use crypto++ to generate an md5sum of a file, and it
works .. as in it provides me with a hash for the file.  My one point
of concern is that an md5sum <file> doesn't give me the same hash.

Your code works fine for me using RHEL 5.4 x86_64 and Crypto++ 5.6.0.

[u...@host HelloWorld]$ dd if=/dev/urandom of=test.rand bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 22.2437 seconds, 4.7 MB/s
[u...@host HelloWorld]$ ./+HelloWorld
MD5:  5a 7b e5 40 e7 e3 bd b8 57 89 04 4d d9 26 32 a5
[u...@host HelloWorld]$ md5sum test.rand
5a7be540e7e3bdb85789044dd92632a5  test.rand


A shorter implementation using Crypto++ would look like this:

#include <crypto++/md5.h>
#include <crypto++/hex.h>
#include <crypto++/files.h>

int main()
{
    std::string result;
    CryptoPP::Weak::MD5 hash;
CryptoPP::FileSource("test.txt",true,new CryptoPP::HashFilter(hash,new CryptoPP::HexEncoder(new CryptoPP::StringSink(result),false)));

    std::cout << result << std::endl;
    return 0;
}

Regards, Peter.

--
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.

Reply via email to