views:

249

answers:

2

Given a "string filename", how can I get the Adler32 checksum using the C++ Crypto++ library. I am a little confused about using their FileSource and Sink system. Below I have the skeleton of the code that does MD5, but I can't seem to find any examples or tutorials on the Adler32 usage.

string filename = "/tmp/data.txt"
string file_adler32_digest;
string file_md5_digest;



MD5 hashMD5;

FileSource( filename.c_str(), 
            true, 
            new HashFilter( hashMD5, 
            new HexEncoder( new StringSink( file_md5_digest ) ) ) );

/* Confusion begins here */   

//how do I do the adler32 ?

/* Confusion ends here */

cout << file_adler32_digest << endl
     << file_md5_digest << endl;


Good samples and sample code here http://www.cryptopp.com/wiki/Category:Sample for all the Crypto++ (except for the Adler32 stuff I want)

A: 

Try this tutorial to get a start with crypto++.

This tutorial is an attempt to get you past the initial hurdles and enable you explore further. By the end of the tutorial you will have written two functional file encryption utilities - one using symmetric encryption and the other using public key encryption.

lothar
@lothar that link is broken for me.
Tim
The server seems down ("ergo.rydlr.net: Socket operation timed out"). I'm sure google will help finding other documantation;-)
lothar
+1  A: 

If you follow this http://www.cryptopp.com/wiki/HashFilter, you have to change hashMD5 for hashAdler32, and file_md5_digest for file_adler32_digest

Adler32 hashAdler32;

FileSource( filename.c_str(), 
            true, 
            new HashFilter( hashAdler32, 
            new HexEncoder( new StringSink( file_adler32_digest ) ) ) );

After this file_adler32_digest should contain the desired hash.

Ismael
That works.. this is weird, I am pretty sure I tried it earlier and posted it here because it didn't. But works now. It's your answering magic that made it work. Thanks!
The Unknown
Yep, this should be some kind of rule: It will not work unless you ask someone else, then it will magically start to work. Tha has happened to me several times :)
Ismael