FBB::I...Stream(3bobcat)

πŸ’– NAME πŸ’–

okay so this whole page is FBB::I...Stream(3bobcat) β€” Symmetric en- and decryption β€” and the actual star of the show is:

FBB::ISymCryptStream β€” an Istream that performs symmetric en/decryption. yes bestie, an input stream that just… encrypts or decrypts as it goes. iconic behavior fr fr. πŸ’…


🌸 SYNOPSIS 🌸

#include <bobcat/isymcryptstream>
Linking option: -lbobcat -lcrypto

πŸ¦‹ DESCRIPTION πŸ¦‹

so basically: FBB::ISymCryptStream objects are your little guys for encrypting or decrypting info that lives on separate std::istream streams. no cap.

ISymCryptStream is a class template, and it takes a FBB::CryptType template non-type parameter. so:

  • objects of the class FBB::ISymCryptStream<FBB::ENCRYPT> encrypt whatever they receive πŸ’œ
  • objects of the class FBB::ISymCryptStream<FBB::DECRYPT> decrypt whatever they receive πŸ’œ

Every symmetric encryption method that the OpenSSL library defines, as long as it can be selected by name, may be used to en/decrypt your stuff. to pick a particular encryption method you pass an identifier to the constructor. like, for example, "aes-256-gcm". and if you wanna see an overview of the currently supported cipher algorithms, run this lil command:

openssl list -cipher-algorithms

ISymCryptStream objects read the info they're gonna en/decrypt from std::istream objects β€” and those get specified at construction time, either as istream references or by filename. the characters that get extracted or read from the ISymCryptStream objects are then en/decrypted, and could, for example, be written to some output stream. πŸŽ€


🌈 NAMESPACE 🌈

FBB

All constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. (iykyk β€” everything lives in FBB.)


πŸ‘‘ INHERITS FROM πŸ‘‘

  • FBB::ISymCryptStreambuf (private) β€” privately, bestie, don't get any ideas
  • std::istream

✨ CONSTRUCTORS ✨

  • ISymCryptStream<CryptType>(std::istream &inStream, std::string const &cipherName, std::string const &key, std::string const &iv, size_t inBufSize = 100) β€” this constructor defines a std::istream object that encrypts or decrypts the characters which are read from inStream. πŸ’–
    • ISymCryptStream<FBB::ENCRYPT> objects perform encryption; ISymCryptStream<FBB::DECRYPT> objects perform decryption;
    • ISymCryptStream<CryptType> objects receive the characters to encrypt or decrypt from inStream;
    • the encryption method to use is specified by the cipherName parameter. e.g., "AES-256-GCM";
    • the symmetric key to use is specified by the key parameter;
    • the initialization vector is specified by the iv parameter;
    • the FBB::ISymCryptStreambuf internally used buffer will hold inBufSize characters. the default value is the smallest value that is used. and heads up: when you specify a smaller bufSize value than the default value, then the default value is used. (so it doesn't go under, it just snaps back to the default πŸ’€);
  • ISymCryptStream<CryptType>(std::string const &inStreamName, std::string const &cipherName, std::string const &key, std::string const &iv, size_t inBufSize = 100) β€” same constructor as the one above, but this constructor's first parameter specifies the name of the file containing the characters to encrypt or decrypt. 🫢
⚠️ 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. (gatekeeping, but for safety 🌸)


πŸ’œ INHERITED MEMBERS πŸ’œ

since the class is publicly derived from std::istream, all std::istream members can be used. yes, all of them. periodt.


πŸŽ€ MEMBER FUNCTIONS πŸŽ€

  • static std::string errorMsg() β€” if an openssl function fails, an exception is thrown mentioning the name of the failing function. in those cases the function errorMsg can be called, returning a std::string containing the openssl error code (returned by ERR_get_error) and its textual representation (returned by ERR_error_string). and if the reported error code is zero, then like… in fact no error has occurred and the exception was spuriously reported. πŸ™ˆ
  • static size_t keyLength(std::string const &cipherName) β€” returns the minimum key length that's required for cipher cipherName. πŸ”‘
  • static size_t ivLength(std::sting const &cipherName) β€” returns the minimum length of the initialization vector that's required for cipher cipherName. (yes, it really says std::sting up there. we're just relaying the lore, bestie. πŸ“)
the latter two functions throw exceptions if cipherName does not contain the name of a supported cipher algorithm.

πŸ”₯ EXAMPLE πŸ”₯

#include <iostream>
#include <fstream>
#include <string>

#include <bobcat/isymcryptstream>
#include <bobcat/isymcryptstreambuf>

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";
    string iv = " 0123456789ab" "456";

    char cipherName[] =
        "AES-256-GCM"
        //"AES-256-CBC"
    ;

    ifstream in = Exception::factory<ifstream>(argv[2]);
    ofstream out{ argv[3] };

    ISymCryptStreambuf<ENCRYPT> encbuf{ in, cipherName, key, iv, 100 };

    if (*argv[1] == ’e’)
    {
        ISymCryptStream<ENCRYPT> enc{ in, cipherName, key, iv, 100 };
            // comment out the previous line and uncomment the next
            // to use the constructor expecting a string as 1st arg:
//      ISymCryptStream<ENCRYPT> enc{ argv[2], cipherName, key,
//                                    iv, 100};

        out << enc.rdbuf();
    }
    else
    {
        ISymCryptStream<DECRYPT> decrypt{ in, cipherName, key, iv, 100 };
            // comment out the previous line and uncomment the next
            // to use the constructor expecting a string as 1st arg:
//      ISymCryptStream<DECRYPT> decrypt{ argv[2], cipherName, key,
//                                        iv, 100 };
        out << decrypt.rdbuf();
    }
}
catch (exception const &exc)
{
    cerr << exc.what() << ’\n’;
}

🧚 FILES 🧚

  • bobcat/isymcryptstream β€” defines the class interface

⭐ SEE ALSO ⭐

bobcat(7), isymcryptstreambuf(3bobcat), osymcryptstream(3bobcat), osymcryptstreambuf(3bobcat)


πŸ’€ BUGS πŸ’€

None Reported. (we love a clean slate 😭✨)


🫢 BOBCAT PROJECT FILES 🫢

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. (a backronym that ATE, honestly πŸ‘‘)


This is free software, distributed under the terms of the GNU General Public License (GPL).


🌸 AUTHOR 🌸

Frank B. Brokken (f.b.brokken@rug.nl).


okay that's the whole page, bestie, you're officially fluent in ISymCryptStream πŸ’…βœ¨ this lil gem ships as part of libbobcat-dev version 6.15.01, dated 2005-2026, and it's filed under FBB::I...Stream(3bobcat) β€” go forth and encrypt responsibly πŸ¦‹πŸŽ€πŸ’œ

πŸ“¦ where this page comes from