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.
I'm reading a file into memory, then running the md5 algorithm on the
string. Should I be doing anything differently?
This is my very simple code so far:
#include <iostream>
#include <string>
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
#include <md5.h>
#include <iomanip>
#include <fstream>
using namespace CryptoPP;
int main(int argc, char *argv[])
{
Weak1::MD5 hash;
byte md5[Weak1::MD5::DIGESTSIZE];
int length =0;
char * buffer;
std::ifstream file;
file.open("bin/rash.png", std::ios::binary);
file.seekg(0, std::ios::end);
length = file.tellg();
file.seekg(0, std::ios::beg);
buffer = new char[length];
file.read(buffer, length);
file.close();
hash.CalculateDigest(md5, (unsigned char *)buffer, length);
std::cout << "MD5: ";
for(int i=0; i<Weak1::MD5::DIGESTSIZE; i++)
{
std::cout << std::hex << std::setfill('0') << std::setw(2) <<
(unsigned short)(md5[i]) << " ";
}
std::cout << std::endl;
delete [] buffer;
return 0;
}
--
--
Samir Faci
*insert title*
fortune | cowsay -f /usr/share/cows/tux.cow
--
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.