Base64Decode:如何获取数据

发布于 2024-11-05 21:21:37 字数 200 浏览 0 评论 0原文

这似乎是一个简单的问题,但 crypto++ 似乎是以一种时髦的、“尽可能迟钝”的方式设计的,所以我想知道......

我怎样才能从 CryptoPP:: 中获取二进制数据Base64Decode 对象?假设我不想将其写入文件或以其他方式对其进行编码,我如何获取实际的二进制数据?

编辑:弄清楚了;不知道如何关闭/删除它,有人吗?我现在在这里做什么合适?

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, anyone? What's the appropriate thing for me to do here now?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与君绝 2024-11-12 21:21:37

没关系,想通了。作为参考,我想获取 BufferedTransformation 子类的 MaxRetrievable 和 Get 方法。

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

夜访吸血鬼 2024-11-12 21:21:37

这似乎是一个简单的问题,但 crypto++ 似乎是
以一种时髦的、“尽可能迟钝”的方式设计,所以我想知道......

如果您不熟悉 Crypto++ 设计,这不是一个简单的问题。实际上有两种设计在起作用。

首先是经典的更新/最终。它在 Crypto++ 中通过 PutGet 等实现。

二是管道设计。这就是数据从源流向接收器的地方,您将看到它,例如:

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

管道相当于 Unix 命令:

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

管道概括为:

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

在内部,源将在第一个过滤器上调用 Put ;第一个过滤器将转换数据并在第二个过滤器上调用 Put,依此类推。最后一个过滤器将在 Sink 上调用 Put。更准确地说,源和过滤器将调用 Put2,但这是一个实现细节。

如果没有Sink:

Source -> Filter -> NULL

那么Filter会在内部缓冲转换后的数据。您可以使用 GetGetWord16GetWord32MaxRetrievableAnyRetrievable 等来从过滤器或接收器中提取数据。

PutGetMaxRetrievable 等都是 BufferedTransformation 接口的一部分,这是一个所有过滤器和接收器实现(实际上不需要源来实现它)。如果一个类不提供 PutGet 等功能,那么它就不是过滤器或接收器。该类的文档位于 BufferedTransformation 类参考

它还有很多功能,包括阻塞和泵送数据块,但 Base64 过滤器或对象并不真正需要它。上例中的pumpAll表示一次性推送所有数据。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文