I had something sitting around that shows how to do it with a FileSource
and a HashFilter:

http://pastebin.com/1BWf99zj

Obviously, this isn't a good example of error checking or exception
handling.

If you only want sha1, ignore the ChannelSwitch stuff and just pass

new HashFilter(sha1, new HexEncoder(new StringSink(sha1val)))

where the sinks parameter to the FileSource constructor is.

This is not better than JPM's sample; it  just happens to use the library a
little differently and demonstrates a couple of features I like.
Use it for any purpose you want, including adding to the crypto++ wiki :)

Geoff

On Fri, Oct 16, 2015 at 1:51 PM, Jean-Pierre Münch <
[email protected]> wrote:

> This is the simplest version I could think of. This may not be optimal and
> may not use the full power of Crypto++ (maybe Jeffrey knows more).
>
> BR
>
> JPM
>
> Code:
>
> // returns the hash, reads from In and forwards In to Out
> SecByteBlock sha1stream(std::fstream<byte>& In, std::fstream<byte>& Out) // 
> out may be optional for you
> {
>       byte buffer; // do it byte-by-byte
>       CryptoPP::Weak::SHA1 Instance; // you must omit the "Weak" if you're 
> using <=5.6.2
>       while(In.get(buffer)) // returns true if successful and false otherwise
>       {
>               Instance.Update(buffer,1); //process
>               Out.write(buffer,1); // pass to next "consumer"
>       }
>       buffer=0; //clean buffer up
>       FixedSizeSecBlock<byte,20> Output; // we know the size in advance
>       Instance.Final(Output);
>       return Output;
> }
>
>
> Am 16.10.2015 um 14:10 schrieb Goran:
>
> Hi all,
>
> I'm using Crypto++ the first time and wondering how I can get the sha1sum
> of a simple std::fstream?
>
> Thanks
> --
> --
> 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>http://www.cryptopp.com.
> ---
> You received this message because you are subscribed to the Google Groups
> "Crypto++ Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> --
> 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.
> ---
> You received this message because you are subscribed to the Google Groups
> "Crypto++ Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
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.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to