开发者

Base64Decode: How to get the data

This seems like it would be an easy question, but crypto++ seems to be designed in a funky, "as obtuse as possible" sorta way, so I'm wondering...

How can I get the binary data out of the CryptoPP::Base64Decode object? Assuming I don't want to write it to a file, or encode it some other way, how do I just get at the actual binary data?

Edit: figured it out; not sure how to close/delete it,开发者_如何学Python anyone? What's the appropriate thing for me to do here now?


Nevermind, figured it out. For reference, I wanted to get the MaxRetrievable and Get methods of the BufferedTransformation subclass.


This seems like it would be an easy question, but crypto++ seems to be designed in a funky, "as obtuse as possible" sorta way, so I'm wondering...

Its not an easy question if you are not familiar with the Crypto++ design. There's actually two designs at work.

First is a classical Update/Final. Its implemented in Crypto++ with Put and Get and friends.

The second is a pipleline design. That's where data flows from source to sink, and you'll see it as, for example:

FileSource fs( "Hello World", true /*pumpAll*/
    new HexEncoder( e,
        new FileSink( "encoded.txt" )     
); // FileSource

The pipeline is equivalent to Unix commands:

echo "Hello World" | base64 >> encoded.txt

The pipeline generalizes to:

Source -> Filter -> Filter -> ... -> Filter -> Sink

Internally, Source will call Put on the first filter; the first filter will transform the data and call Put on the second filter, and so on. The last filter will call Put on the Sink. More correctly, the Source and Filters will call Put2, but that's an implementation detail.

If there is no Sink:

Source -> Filter -> NULL

then the Filter will internally buffer the transformed data. You can use Get, GetWord16, GetWord32, MaxRetrievable, AnyRetrievable, etc to extract data from the filter or sink.

Put, Get, MaxRetrievable and friends are part of the BufferedTransformation interface, and that's an interface that all filters and sinks implement (there's really no need for a source to implement it). If a class does not provide Put, Get and friends, then its not a filter or sink. Documentation for the class is located at BufferedTransformation Class Reference.

There's a lot more to it, including blocking and pumping data in blocks, but its not really needed for a Base64 filter or object. The pumpAll in the above example means to push all data at once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜