Encryption

This Entry describes supported encryption methods. Its is more efficient and easier to use these Models in combination with the keyring and cryptosys class. Because they handle the entire encryption process and make sure the classes always have the right input size.

Key Class

#include <Zostera/Key.h>

CKeyWrapper is essentialy the wrapper class for all encryption methods. It has 2 usefull functions for the user.

class CKeyWrapper

Subclassed by Zostera::AES, Zostera::RSA_PRIVATE, Zostera::RSA_PUBLIC

Public Functions

virtual std::string exportKey() = 0

Returns the Key has Hex encoded string.

virtual int readKey(const char *) = 0

Creates the internal Key structure based on the given file.

Parameters
  • path: Path to a given valid keyfile.

virtual int writeKey(const char *) = 0

Saves the internal Key structure into a given file.

Parameters
  • path: Path (string) where the keyfile should be created / exists.

virtual int writeKey(std::ofstream&) = 0

Saves the internal Key structure into a given file.

Parameters
  • path: iostream which piplines data into the desired file.

virtual int readKey(std::istream&) = 0

Creates the internal Key structure based on the given file.

Parameters
  • path: iostream which provides data of the desired keyfile..

virtual std::string encrypt(std::string&) = 0

Encrypts the given string.

Parameters
  • message: PlainText Message

virtual std::string decrypt(std::string&) = 0

Decrypts the given string.

Parameters
  • message: Cipher Text Message

virtual std::tuple<CryptoPP::byte *, size_t> encrypt(std::tuple<CryptoPP::byte *, size_t>) = 0

Encrypts the given data.

Parameters
  • message: Tuple of a CryptoPP::byte pointer and the corresponding length (Plaintext).

virtual std::tuple<CryptoPP::byte *, size_t> decrypt(std::tuple<CryptoPP::byte *, size_t>) = 0

Decrypts the given data.

Parameters
  • message: Tuple of a CryptoPP::byte pointer and the corresponding length (Ciphertext).

std::tuple<char *, size_t> encrypt(std::tuple<char *, size_t> input) = 0

Encrypts the given data.

This Function converts your

char * into the internal used CryptoPP::byte* and calls the normal byte encryption method. char * is the pointer too your byte array and size_t is the corresponding length. So consider you do it manually
Parameters
  • input: Tuple of a char pointer and the corresponding length (Plaintext).

std::tuple<char *, size_t> decrypt(std::tuple<char *, size_t> input) = 0

Decrypts the given data.

This Function converts your

char * into the internal used CryptoPP::byte* and calls the normal byte encryption method. char * is the pointer too your byte array and size_t is the corresponding length. So consider you do it manually
Parameters
  • input: Tuple of a char pointer and the corresponding length (Ciphertext).

virtual std::tuple<unsigned int, unsigned int, std::string> expectedInputSize() = 0

Returns important relevant information about the encryption method.

This Function returns the max input size, blocksize and the typ of encryption method (BLOCK, ASYNC)

Public Members

std::string str_procedure

Representing the typ of method.

Block Ciphers

AES

#include <Zostera/aes.h>

AES is a block cipher which has a block size of 16 bytes.

class AES : public Zostera::CKeyWrapper

Public Functions

int generateRandomAes(unsigned long)

Generates Random AES Key and Init Vector based on the given key strength;.

Parameters
  • input_key_strength: unsigned char Key strength

int setKey(const std::string &istr_key)

Sets your own key as one randomly generated one pls make sure it is 16 bytes long.

Parameters
  • key: std::string New key

std::string exportKey()

Exports the Key as HEX encoded string.

int writeKey(const char *path)

Writes your AES Key into the file given by the path.

Parameters
  • path: Path to the file.

int readKey(const char *path)

Creates the AES Key based on the given path to a file.

Parameters
  • path: Path to the keyfile

int writeKey(std::ofstream &keyfile)

Saves the AES Key into the file given by the stream.

Parameters
  • path: ofstream

int readKey(std::istream &keyfile)

Creates the Private Key based on the given stream.

Parameters
  • path: ifsteam

std::string encrypt(std::string &message)

Encrypts the given plain text.

Parameters
  • message: std::string plaintext message

std::string decrypt(std::string &cipher)

Decrypts the given cipher text.

Parameters
  • message: ciphertext

std::tuple<CryptoPP::byte *, size_t> encrypt(std::tuple<CryptoPP::byte *, size_t> plaintext)

Encrypts the given plain text.

Parameters
  • message: tuple made of CryptoPP::byte* pointer and the length of the text.

std::tuple<CryptoPP::byte *, size_t> decrypt(std::tuple<CryptoPP::byte *, size_t> cipher)

Decrypts the given cipher text.

Parameters
  • message: tuple made of CryptoPP::byte* pointer and the length of the text.

std::tuple<unsigned int, unsigned int, std::string> expectedInputSize()

Returns important relevant information about this AES Key.

This Function returns the max input size (1), blocksize (16), and encryption method (BLOCK)

Asyncrone Ciphers

#include <Zostera/rsa.h>

Encrypting / Decrypting with the wrong key will throw you an ZosteraExcpetion be aware of that.

RSA Private Key

class RSA_PRIVATE : public Zostera::CKeyWrapper

Public Functions

Zostera::RSA_PUBLIC *generate_private_rsa(size_t intBitLength)

Generates your private key and a public Key.

Parameters
  • int_bit_length: Bit key strength

std::string exportKey()

Exports your Private Keys as Hex Encoded string.

int writeKey(const char *path)

Writes your Private Key into the file given by the path.

Parameters
  • path: Path to the file.

int readKey(const char *path)

Creates the Private Key based on the given path to a file.

Parameters
  • path: Path to the keyfile

int writeKey(std::ofstream &outfile)

Saves the Private Key into the file given by the stream.

Parameters
  • path: ofstream

int readKey(std::istream &input_file)

Creates the Private Key based on the given stream.

Parameters
  • path: ifsteam

std::string decrypt(std::string &cipher)

Decrypts the given cipher text.

Parameters
  • message: ciphertext

std::string encrypt(std::string&)

Warning

DO NOT CALL THIS METHOD IT WILL THROW YOU AN ZOSTERA EXCEPTION: YOU CAN NOT ENCRYPT WITH A PRIVATE KEY

std::tuple<CryptoPP::byte *, size_t> decrypt(std::tuple<CryptoPP::byte *, size_t> cipher)

Decrypts the given cipher text.

Parameters
  • message: tuple made of CryptoPP::byte* pointer and the length of the text.

std::tuple<CryptoPP::byte *, size_t> encrypt(std::tuple<CryptoPP::byte *, size_t>)

Warning

DO NOT CALL THIS METHOD IT WILL THROW YOU AN ZOSTERA EXCEPTION: YOU CAN NOT ENCRYPT WITH A PRIVATE KEY

std::tuple<unsigned int, unsigned int, std::string> expectedInputSize()

Returns important relevant information about this Private Key.

This Function returns the max input size, blocksize (1), and encryption method (ASYNC)

RSA Public Key

class RSA_PUBLIC : public Zostera::CKeyWrapper

Public Functions

std::string exportKey()

Exports your Public Keys as Hex Encoded string.

int writeKey(const char *path)

Writes your Public Key into the file given by the path.

Parameters
  • path: Path to the file.

int readKey(const char *path)

Creates the Public Key based on the given path to a file.

Parameters
  • path: Path to the keyfile

int writeKey(std::ofstream &outfile)

Saves the Public Key into the file given by the stream.

Parameters
  • path: ofstream

int readKey(std::istream &input_file)

Creates the Public Key based on the given stream.

Parameters
  • path: ifsteam

std::string decrypt(std::string&)

Warning

DO NOT CALL THIS METHOD IT WILL THROW YOU AN ZOSTERA EXCEPTION: YOU CAN NOT DECRYPT WITH A PUBLIC KEY

std::string encrypt(std::string &message)

Encrypts the given plain text.

Parameters
  • message: std::string plaintext message

std::tuple<CryptoPP::byte *, size_t> decrypt(std::tuple<CryptoPP::byte *, size_t>)

Warning

DO NOT CALL THIS METHOD IT WILL THROW YOU AN ZOSTERA EXCEPTION: YOU CAN NOT DECRYPT WITH A PUBLIC KEY

std::tuple<CryptoPP::byte *, size_t> encrypt(std::tuple<CryptoPP::byte *, size_t> plaintext)

Encrypts the given plain text.

Parameters
  • message: tuple made of CryptoPP::byte* pointer and the length of the text.

std::tuple<unsigned int, unsigned int, std::string> expectedInputSize()

Returns important relevant information about this Public Key.

This Function returns the max input size, blocksize (1), and encryption method (ASYNC)