ArraySink

From Crypto++ Wiki
Jump to: navigation, search
ArraySink
Documentation
#include <cryptopp/filters.h>

In the pipelining paradigm, Sinks are a destination endpoint.

Example

Hash the string "Wikipedia" with adler32, and store the result in a std::array of bytes

const int ADLER32_BYTES = 4;
CryptoPP::Adler32 hash;
std::array<byte, ADLER32_BYTES> output;
CryptoPP::StringSource( "Wikipedia", true,
                        new CryptoPP::HashFilter( hash, 
                            new CryptoPP::ArraySink(output.data(), ADLER32_BYTES)
                        )
                      );
for(auto &it: output){
    // We have to cast to int, or else it will interpret the byte as ascii
    std::cout << (int)it << " ";
}
std::cout << std::endl;

Output:

17 230 3 152

Which, when converted to Hexadecimal, reads: 11, E6, 03, 98 which lines up with the Wikipedia article on Adler32.