FBB::DecryptBuf(3bobcat) | Decrypt information | FBB::DecryptBuf(3bobcat) |
FBB::DecryptBuf - Decrypts information using various methods into a std::ostream
#include <bobcat/decryptbuf>
Linking option: -lbobcat -lcrypto
FBB::DecryptBuf objects are std::streambuf objects that can be used to initialize std::ostream objects.
All information inserted into such an std::ostream is decrypted and written to an std::ostream passed as argument to DecryptBuf’s constructor.
All encryption methods supported by the OpenSSL library that can be selected by name may be used by DecryptBuf objects. In practice the information has previously been encrypted by an EncryptBuf object, using the same encryption method. Likewise, the constructor expects a key and initialization vector. The key and initialization vector that was passed to the EncryptBuf object must be passed to DecryptBuf’s constructor as well.
Block ciphers use one of the following four encryption modes:
The following table presents an overview of methods that are currently available. Methods for which the block size is specified as N.A. are stream ciphers; other methods are block ciphers:
method | keysize | blocksize | mode | identifier |
(bytes) | (bytes) | |||
AES | 16 | 8 | CBC | "aes-128-cbc" |
EBC | "aes-128-ecb" | |||
CFB | "aes-128-cfb" | |||
OFB | "aes-128-ofb" | |||
24 | 24 | CBC | "aes-192-cbc" | |
EBC | "aes-192-ecb" | |||
CFB | "aes-192-cfb" | |||
OFB | "aes-192-ofb" | |||
32 | 32 | CBC | "aes-256-cbc" | |
EBC | "aes-256-ecb" | |||
CFB | "aes-256-cfb" | |||
OFB | "aes-256-ofb" | |||
BLOWFISH | 16 | 8 | CBC | "bf-cbc" |
EBC | "bf-ecb" | |||
CFB | "bf-cfb" | |||
OFB | "bf-ofb" | |||
max key length is 56 bytes, 16 generally used | ||||
CAMELLIA | 16 | 16 | CBC | "camellia-128-cbc" |
EBC | "camellia-128-ecb" | |||
CFB | "camellia-128-cfb" | |||
OFB | "camellia-128-ofb" | |||
24 | CBC | "camellia-192-cbc" | ||
EBC | "camellia-192-ecb" | |||
CFB | "camellia-192-cfb" | |||
OFB | "camellia-192-ofb" | |||
32 | CBC | "camellia-256-cbc" | ||
EBC | "camellia-256-ecb" | |||
CFB | "camellia-256-cfb" | |||
OFB | "camellia-256-ofb" | |||
CAST | 16 | 8 | CBC | "cast-cbc" |
EBC | "cast-ecb" | |||
CFB | "cast-cfb" | |||
OFB | "cast-ofb" | |||
min key length is 5 bytes, max is shown | ||||
DES | 8 | 8 | CBC | "des-cbc" |
EBC | "des-ebc" | |||
CFB | "des-cfb" | |||
OFB | "des-ofb" | |||
DESX | 8 | 8 | CBC | "desx-cbc" |
3DES | 16 | 8 | CBC | "des-ede-cbc" |
EBC | "des-ede" | |||
CFB | "des-ede-cfb" | |||
OFB | "des-ede-ofb" | |||
3DES | 24 | 8 | CBC | "des-ede3-cbc" |
EBC | "des-ede3" | |||
CFB | "des-ede3-cfb" | |||
OFB | "des-ede3-ofb" | |||
Key bytes 9-16 define the 2nd key, bytes 17-24 | ||||
define the 3rd key | ||||
RC2 | 16 | 8 | CBC | "rc2-cbc" |
EBC | "rc2-ecb" | |||
CFB | "rc2-cfb" | |||
OFB | "rc2-ofb" | |||
Key length variable, max. 128 bytes, default length is shown | ||||
RC2-40 | 5 | 8 | "rc2-40-cbc" | |
obsolete: avoid | ||||
RC2-64 | 8 | 8 | "rc2-64-cbc" | |
obsolete: avoid | ||||
RC4 | 16 | N.A. | "rc4" | |
Key length is variable, max. 256 bytes. default length is shown | ||||
Encrypt again to decrypt. Don’t use DecryptBuf | ||||
RC4-40 | 5 | N.A. | "rc4-40" | |
obsolete: avoid | ||||
RC5 | 16 | 8 | CBC | "rc5-cbc" |
EBC | "rc5-ecb" | |||
CFB | "rc5-cfb" | |||
OFB | "rc5-ofb" | |||
Key length variable, max. 256 bytes, rounds 8, 12 or 16, | ||||
default # rounds is 12 | ||||
The RC4 stream cipher is subject to a well-known attack (cf. http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Mantin1.zip) unless the initial 256 bytes produced by the cipher are discarded.
FBB
All constructors, members, operators and manipulators, mentioned in this
man-page, are defined in the namespace FBB.
FBB::CryptBuf, in turn inheriting from std::streambuf
completes the decryption once DecryptBuf’s destructor is called. Alternatively,
decStream << encStream.rdbuf();
can be used to immediately complete the decryption process.
desStream << encStream.rdbuf() << eoi;
Copy and move constructors (and assignment operators) are not available.
All members of std::streambuf are available, as FBB::DecryptBuf inherits from this class.
#include <iostream> #include <fstream> #include <bobcat/exception> #include <bobcat/ohexbuf> #include <openssl/evp.h> #include <openssl/err.h> #include "../decryptbuf" #include "../../encryptbuf/encryptbuf" using namespace std; using namespace FBB; int main(int argc, char **argv) try {
if (argc == 1)
throw Exception(1) <<
"1st arg: method, 2nd arg: key, 3rd arg: iv, "
"4th arg: file to decrypt (to stdout)";
// e.g., driver aes-128-cbc somekey iv-from-encryptbuf-driver
// /tmp/enc > /tmp/driver.dec
cerr << "Key: `" << argv[2] << "’\n"
"IV: `" << argv[3] << "’\n";
DecryptBuf decryptbuf(cout, argv[1], argv[2], argv[3]);
ostream out(&decryptbuf);
ifstream in(argv[4]);
if (not in)
throw Exception{} << "can’t read `" << argv[4] << ’\n’;
out << in.rdbuf() << eoi; } catch(exception const &err) {
cout << err.what() << endl;
return 1; }
bobcat/decryptbuf - defines the class interface
bobcat(7), encryptbuf(3bobcat), std::streambuf
None reported
Bobcat is an acronym of `Brokken’s Own Base Classes And Templates’.
This is free software, distributed under the terms of the GNU General Public License (GPL).
Frank B. Brokken (f.b.brokken@rug.nl).
2005-2020 | libbobcat-dev_5.07.00 |