解密部分 AES 加密文件
Decrypting portions of AES encrypted file
对于我的 C++ 应用程序,我查看了 Crypto++。似乎很简单,可以加密一些内容并将其保存在文件中。解密整个文件似乎也很简单。但是,我们的要求是我们不能一次解密整个文件。我需要根据调用者的要求即时解密部分文件。本质上,我需要实现以下伪方法:
int openFile(const char* aesFile); // returns a handle
long read(int handle, long pos, int size, byte* buffer);
我怎样才能做到这一点? Crypto++ 或其他一些库中是否有现成的东西可以做到这一点?问候。
How can I achieve this? Is there something in Crypto++ ...
我认为你需要两件事。首先,您需要一个 seekable 密码操作模式。 Counter mode (CTR) will probably work for that. You can check if a cipher is seekable using IsRandomAccess(). Its inherited from StreamTransfoormation Class.
在计数器模式(和其他可搜索模式)下,请小心确保您仍然有真实性保证。这可能很棘手。另见 Authenticated Encryption on the Crypto++ wiki.
其次,可能你需要避免流接口,你需要使用Put
和Get
。 Put
和 Get
只是 C-like class 每个 Crypto++ BufferedTransformation
class 上的函数。
Put
和Get
[的大多数示例=52=] 相当琐碎。然而,最近 Crypto++ wiki at Init-Update-Final 上出现了一个更重要的东西。虽然它更丰富,但它并不复杂,因为它是一个简单的概念。
... or some other library that is readily available to do this?
嗯,这是你必须做出的选择。如果 C++ 和安全库是您唯一的库需求,那么您还可以查看 Jack Lloyd's Botan.
对于我的 C++ 应用程序,我查看了 Crypto++。似乎很简单,可以加密一些内容并将其保存在文件中。解密整个文件似乎也很简单。但是,我们的要求是我们不能一次解密整个文件。我需要根据调用者的要求即时解密部分文件。本质上,我需要实现以下伪方法:
int openFile(const char* aesFile); // returns a handle
long read(int handle, long pos, int size, byte* buffer);
我怎样才能做到这一点? Crypto++ 或其他一些库中是否有现成的东西可以做到这一点?问候。
How can I achieve this? Is there something in Crypto++ ...
我认为你需要两件事。首先,您需要一个 seekable 密码操作模式。 Counter mode (CTR) will probably work for that. You can check if a cipher is seekable using IsRandomAccess(). Its inherited from StreamTransfoormation Class.
在计数器模式(和其他可搜索模式)下,请小心确保您仍然有真实性保证。这可能很棘手。另见 Authenticated Encryption on the Crypto++ wiki.
其次,可能你需要避免流接口,你需要使用Put
和Get
。 Put
和 Get
只是 C-like class 每个 Crypto++ BufferedTransformation
class 上的函数。
Put
和Get
[的大多数示例=52=] 相当琐碎。然而,最近 Crypto++ wiki at Init-Update-Final 上出现了一个更重要的东西。虽然它更丰富,但它并不复杂,因为它是一个简单的概念。
... or some other library that is readily available to do this?
嗯,这是你必须做出的选择。如果 C++ 和安全库是您唯一的库需求,那么您还可以查看 Jack Lloyd's Botan.