FBB::O...Stream(3bobcat)
π NAME π
okay so real quick bestie, you're reading FBB::O...Stream(3bobcat) and the star of the show is FBB::OSymCryptStream β it's literally a std::ostream that performs symmetric en/decryption. a stream that does crypto. main character energy, no cap πβ¨
π SYNOPSIS π
#include <bobcat/osymcryptstream>
Linking option: -lbobcat -lcrypto
π¦ DESCRIPTION π¦
FBB::OSymCryptStream objects can be used to encrypt or decrypt information, that is available on separate std::istream streams. like, the info lives somewhere else and your stream does the glow-up on the way out π
The class OSymCryptStream is a class template, using a FBB::CryptType template non-type parameter. Objects of the class FBB::OSymCryptStream<FBB::ENCRYPT> encrypt the information they receive, objects of the class FBB::OSymCryptStream<FBB::DECRYPT> decrypt the information they receive. ENCRYPT girlies and DECRYPT girlies, both valid, both iconic π
All symmetric encryption methods defined by the OpenSSL library that can be selected by name may be used to en/decrypt information. To select a particular encryption method an identifier is passed to the constructor. E.g., "aes-256-gcm". For the currently supported cipher algorithms issue the command:
openssl list -cipher-algorithms
OSymCryptStream objects read the information to en/decrypt from an external source (e.g., from std::istream objects). The characters that are encrypted or decrypted by OSymCryptStream objects are written to std::ostream objects which are at construction-time specified as ostream references or by filename. pick your fave delivery method bestie π«Ά
π§ NAMESPACE π§
FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB. periodt.
π INHERITS FROM π
FBB::OSymCryptStreambuf(private) πstd::istream
β¨ CONSTRUCTORS β¨
OSymCryptStream<CryptType>(std::ostream &outStream, std::string const &cipherName, std::string const &key, std::string const &iv, size_t inBufSize = 100)β this constructor defines astd::streambufencrypting or decrypting the characters it receives. the way that it just does that:OSymCryptStream<FBB::ENCRYPT>objects perform encryption;OSymCryptStream<FBB::DECRYPT>objects perform decryption;OSymCryptStream<CryptType>objects write the encrypted or decrypted characters tooutStream;- the encryption method to use is specified by the
cipherNameparameter. E.g.,"AES-256-GCM"; - the symmetric key to use is specified by the
keyparameter; - the initialization vector is specified by the
ivparameter; - the
FBB::OSymCryptStreambufinternally used buffer will holdinBufSizecharacters. The default value is the smallest value that is used. When specifying a smallerbufSizevalue the default value is used.
OSymCryptStream<CryptType>(std::string const &outStreamName, std::string const &cipherName, std::string const &key, std::string const &iv, size_t inBufSize = 100)β same constructor as the previous one, but this constructor's first parameter specifies the name of the file to receive the encrypted or decrypted characters. same vibes, file edition π
If the construction fails an exception is thrown, mentioning the openssl function that failed to complete (see also errorMsg below).
The move constructor is available, the copy constructor and assignment operators are not available, π (yes, exactly like that, with the little comma)
πΈ INHERITED MEMBERS πΈ
Since the class is publicly derived from std::ostream, all std::ostream members can be used. everything your ostream can do, she can do too, she just has secrets π₯
π MEMBER FUNCTIONS π
static std::string errorMsg()β if anopensslfunction fails an exception is thrown mentioning the name of the failing function. In those cases the functionerrorMsgcan be called returning astd::stringcontaining theopensslerror code (returned byERR_get_error) and its textual representation (returned byERR_error_string). If the reported error code is zero, then in fact no error has occurred and the exception was spuriously reported π (not her being dramatic for no reason)static size_t keyLength(std::string const &cipherName)β returns the minimum key length required for ciphercipherName;static size_t ivLength(std::sting const &cipherName)β returns the minimum length of the initialization vector that is required for ciphercipherName. (copied character for character bestie, we don't touch the source, iykyk π )
The latter two functions throw exceptions if cipherName does not contain the name of a supported cipher algorithm. so give her a real cipher name or she's gonna be upset π
π MANIPULATOR π
std::ostream &FBB::eoi(std::ostream &out)β by inserting theeoimanipulator into anOSymCryptStreamobject insertion is considered complete. It completes the insertion of information into thestd::ostreamspecified at construction time as theOSymCryptStream's first argument. That way, you don't have to wait until theOSymCryptStreamobject's destructor flushes that stream. In the following example using theeoimanipulator is illustrated in the (commented out lines near line 40):
//in.seekg(0); // when activated, this wonβt
//enc << in.rdbuf(); // be processed due to β<< eoiβ
Activating those lines will not result in processing the in stream twice. one and done, as she should π
β EXAMPLE β
#include <iostream>
#include <fstream>
#include <string>
#include <bobcat/osymcryptstream>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
try
{
if (argc == 1)
{
cout << "arg[1]: e - encrypt, d - decrypt,\n"
"arg[2]: file to process, arg[3]: processed file\n";
return 0;
}
string key = "0123456789abcdef0123456789abcdef";
cout << "encryption key ? ";
cin >> key;
while (key.size() < 32)
key += key;
string iv = " 0123456789ab" "456";
char cipherName[] =
"AES-256-GCM"
//"AES-256-CBC"
;
ifstream in{ argv[2] };
ofstream out{ argv[3] };
if (*argv[1] == βeβ)
{
OSymCryptStream<ENCRYPT> enc{ out, cipherName, key, iv, 100 };
// comment out the above statement and uncomment the next
// to use the constructor expecting a string as 1st arg:
// OSymCryptStream<ENCRYPT> enc{ argv[3], cipherName, key,
// iv, 100 };
enc << in.rdbuf() << eoi;
//in.seekg(0); // when activated, this wonβt
//enc << in.rdbuf(); // be processed due to β<< eoiβ
}
else
{
OSymCryptStream<DECRYPT> decrypt{ out, cipherName, key,
iv, 100 };
// comment out the above statement and uncomment the next
// to use the constructor expecting a string as 1st arg:
// OSymCryptStream<DECRYPT> decrypt{ argv[3], cipherName, key,
// iv, 100 };
decrypt << in.rdbuf() << eoi;
}
}
catch (exception const &exc)
{
cerr << exc.what() << β\nβ;
}
she ate that example fr fr π₯
π FILES π
bobcat/osymcryptstream β defines the class interface
π SEE ALSO π
bobcat(7), isymcryptstream(3bobcat), isymcryptstreambuf(3bobcat), osymcryptstreambuf(3bobcat)
π BUGS π
None Reported. not a single one, we stay winning β¨
π«Ά BOBCAT PROJECT FILES π«Ά
https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
libbobcat6: debian package containing the shared library, changelog and copyright note;libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;
π BOBCAT π
Bobcat is an acronym of Brokkenβs Own Base Classes And Templates. cute AND clever, obsessed π
πΈ COPYRIGHT πΈ
This is free software, distributed under the terms of the GNU General Public License (GPL). free as in bestie, go wild π¦
π AUTHOR π
Frank B. Brokken (f.b.brokken@rug.nl). thank you king π
and that's the whole page bestie, brought to you by libbobcat-dev_6.15.01 β serving documentation since 2005-2026 π
β¨π«Ά
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms