Hi,

I'm new to this, but I hope this is correct. I think that once you have
created your hash filter you can just use the put and get methods to send
binary data.

 md5Filter->Put( your data );
 md5Filter->MessageEnd();
 if (mFilter->AnyRetrievable())
  {
  int outLength = md5Filter->MaxRetrievable();
  char* out = new char[outLength];
  md5Filter->Get((unsigned char*)out, outLength); // The hash value!
  }

Give or take a bit of error checking/memory management :)

There are also existing sinks for strings and buffers, so you wouldn't have
to write your own if you wanted to go that route.


>-- Original Message --
>Date: Thu, 01 May 2003 13:33:24 +1000
>Subject: Simple question...
>From: Matthew Smith <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>
>
>Hello,
>
>I need to hash some data (char *) and would like to get the hash back as
>a
>char *, so far I've come up with (based on the example with the source):
>
>void md5Data(const char *data)
>{
>    MD5 md5;
>    HashFilter md5Filter(md5);
>    auto_ptr<ChannelSwitch> channelSwitch(new ChannelSwitch);
>    channelSwitch->AddDefaultRoute(md5Filter);
>    StringSource(data, true, channelSwitch.release());
>    
>    HexEncoder encoder(new FileSink(cout), false);
>    cout << "\nMD5: ";
>    md5Filter.TransferTo(encoder);
>    cout << "\n";
>}
>
>Now, my (limited) understanding of crypto++ is this:
>
>To get the data as a string (rather then stout), I would need to implement
>a
>class that inherits from Sink, then get the data out of it myself??
>
>I would think that this sort of thing is quite common, is there a better
>way
>of doing it, or something in the lib I am missing???
>
>Cheers
>
>Matt Smith
>

----------------
ImagingStuff.com


Reply via email to