10Duke Enterprise C++ SDK
Loading...
Searching...
No Matches
tenduke::crypto::AbstractCiphers Class Referenceabstract

#include <AbstractCiphers.h>

Detailed Description

Abstract base class for cipher implementations.

This class provides default implementations for convenience methods that delegate to the pure virtual methods defined in the Ciphers interface.

Subclasses must implement the pure virtual methods.

Inheritance diagram for tenduke::crypto::AbstractCiphers:
tenduke::crypto::Ciphers tenduke::crypto::libcrypto::LibcryptoCiphers tenduke::crypto::win::cng::WinCNGCiphers

Public Member Functions

std::unique_ptr<::tenduke::utl::BinaryDatadecrypt (const ::tenduke::utl::DataSpan &ciphertext, const ::tenduke::utl::DataSpan &encryptionKey) const override
 Decrypts given data using the system default cipher (AES256 GCM).
std::string decryptString (const ::tenduke::utl::DataSpan &ciphertext, const ::tenduke::utl::DataSpan &encryptionKey) const override
 Decrypts given data using the system default cipher (AES256 GCM) to a string.This method expects the input to consist of magic (4 bytes) + version (2 bytes) + IV (12 bytes) + ciphertext + tag (16 bytes), i.e., the output produced by calling ::encrypt(key, plaintext).This is "syntactic sugar": The method also performs key-derivation for the provided key to simplify the use.
Parameters
ciphertextthe cipher text (the data to decrypt), the maximum supported length is INT_MAX.
encryptionKeyencryption key
Returns
plain text (decrypted data) as std::string. Good for decrypting a string but also works for binary data

std::unique_ptr<::tenduke::utl::BinaryDataencrypt (const ::tenduke::utl::DataSpan &plaintext, const ::tenduke::utl::DataSpan &encryptionKey) const override
 Encrypts given data using the system default cipher (AES256 GCM).The output consists of magic (4 bytes) + version (2 bytes) + IV (12 bytes) + ciphertext + tag (16 bytes).This is "syntactic sugar": The method also performs key-derivation for the provided key to simplify the use. The method also generates a random IV.
Parameters
plaintextthe plain text (the data to encrypt), the maximum supported length is INT_MAX.
encryptionKeyencryption key
Returns
cipher text (encrypted data)

std::unique_ptr<::tenduke::utl::BinaryDataencrypt (const std::string &plaintext, const ::tenduke::utl::DataSpan &encryptionKey) const override
 Encrypts given data using the system default cipher (AES256 GCM).The output consists of magic (4 bytes) + version (2 bytes) + IV (12 bytes) + ciphertext + tag (16 bytes).This is "syntactic sugar": The method also performs key-derivation for the provided key to simplify the use. The method also generates a random IV.
Parameters
plaintextthe plain text, the maximum supported length is INT_MAX.
encryptionKeyencryption key
Returns
cipher text (encrypted data)

Protected Member Functions

virtual std::unique_ptr<::tenduke::utl::BinaryDatadecryptBytes (const unsigned char *ciphertext, std::size_t ciphertextLength, const unsigned char *encryptionKey, std::size_t encryptionKeyLength) const =0
 Decrypts the data.
virtual std::unique_ptr<::tenduke::utl::BinaryDataencryptBytes (const unsigned char *plaintext, std::size_t plaintextLength, const unsigned char *encryptionKey, std::size_t encryptionKeyLength) const =0
 Encrypts the data.
virtual void writeHeader (unsigned char *buffer, std::uint16_t version) const
 Writes the blob header (magic and version) in network byte order.
virtual std::uint16_t readAndValidateHeader (const unsigned char *buffer, std::size_t bufferLength) const
 Reads and validates the blob header.

Static Protected Attributes

static constexpr std::uint32_t BLOB_MAGIC = 0x44554B45
 Magic value for encrypted blob header.
static constexpr std::size_t BLOB_HEADER_SIZE = 6
 Header size: magic (4 bytes) + version (2 bytes).

Member Function Documentation

◆ decrypt()

std::unique_ptr<::tenduke::utl::BinaryData > tenduke::crypto::AbstractCiphers::decrypt ( const ::tenduke::utl::DataSpan & ciphertext,
const ::tenduke::utl::DataSpan & encryptionKey ) const
inlineoverridevirtual

Decrypts given data using the system default cipher (AES256 GCM).

This method expects the input to consist of magic (4 bytes) + version (2 bytes) + IV (12 bytes) + ciphertext + tag (16 bytes), i.e., the output produced by calling ::encrypt(key, plaintext).

This is "syntactic sugar": The method also performs key-derivation for the provided key to simplify the use.

Parameters
ciphertextthe cipher text (the data to decrypt), the maximum supported length is INT_MAX.
encryptionKeyencryption key
Returns
plain text (decrypted data)

Implements tenduke::crypto::Ciphers.

◆ decryptBytes()

virtual std::unique_ptr<::tenduke::utl::BinaryData > tenduke::crypto::AbstractCiphers::decryptBytes ( const unsigned char * ciphertext,
std::size_t ciphertextLength,
const unsigned char * encryptionKey,
std::size_t encryptionKeyLength ) const
protectedpure virtual

Decrypts the data.

Implementations will implement this method.

Implemented in LibcryptoCiphers, tenduke::crypto::libcrypto::LibcryptoCiphers, and tenduke::crypto::win::cng::WinCNGCiphers.

◆ decryptString()

std::string tenduke::crypto::AbstractCiphers::decryptString ( const ::tenduke::utl::DataSpan & ciphertext,
const ::tenduke::utl::DataSpan & encryptionKey ) const
inlineoverridevirtual

Decrypts given data using the system default cipher (AES256 GCM) to a string.This method expects the input to consist of magic (4 bytes) + version (2 bytes) + IV (12 bytes) + ciphertext + tag (16 bytes), i.e., the output produced by calling ::encrypt(key, plaintext).This is "syntactic sugar": The method also performs key-derivation for the provided key to simplify the use.

Parameters
ciphertextthe cipher text (the data to decrypt), the maximum supported length is INT_MAX.
encryptionKeyencryption key
Returns
plain text (decrypted data) as std::string. Good for decrypting a string but also works for binary data

Implements tenduke::crypto::Ciphers.

◆ encrypt() [1/2]

std::unique_ptr<::tenduke::utl::BinaryData > tenduke::crypto::AbstractCiphers::encrypt ( const ::tenduke::utl::DataSpan & plaintext,
const ::tenduke::utl::DataSpan & encryptionKey ) const
inlineoverridevirtual

Encrypts given data using the system default cipher (AES256 GCM).The output consists of magic (4 bytes) + version (2 bytes) + IV (12 bytes) + ciphertext + tag (16 bytes).This is "syntactic sugar": The method also performs key-derivation for the provided key to simplify the use. The method also generates a random IV.

Parameters
plaintextthe plain text (the data to encrypt), the maximum supported length is INT_MAX.
encryptionKeyencryption key
Returns
cipher text (encrypted data)

Implements tenduke::crypto::Ciphers.

◆ encrypt() [2/2]

std::unique_ptr<::tenduke::utl::BinaryData > tenduke::crypto::AbstractCiphers::encrypt ( const std::string & plaintext,
const ::tenduke::utl::DataSpan & encryptionKey ) const
inlineoverridevirtual

Encrypts given data using the system default cipher (AES256 GCM).The output consists of magic (4 bytes) + version (2 bytes) + IV (12 bytes) + ciphertext + tag (16 bytes).This is "syntactic sugar": The method also performs key-derivation for the provided key to simplify the use. The method also generates a random IV.

Parameters
plaintextthe plain text, the maximum supported length is INT_MAX.
encryptionKeyencryption key
Returns
cipher text (encrypted data)

Implements tenduke::crypto::Ciphers.

◆ encryptBytes()

virtual std::unique_ptr<::tenduke::utl::BinaryData > tenduke::crypto::AbstractCiphers::encryptBytes ( const unsigned char * plaintext,
std::size_t plaintextLength,
const unsigned char * encryptionKey,
std::size_t encryptionKeyLength ) const
protectedpure virtual

Encrypts the data.

Implementations will implement this method.

Implemented in LibcryptoCiphers, tenduke::crypto::libcrypto::LibcryptoCiphers, and tenduke::crypto::win::cng::WinCNGCiphers.

◆ readAndValidateHeader()

virtual std::uint16_t tenduke::crypto::AbstractCiphers::readAndValidateHeader ( const unsigned char * buffer,
std::size_t bufferLength ) const
inlineprotectedvirtual

Reads and validates the blob header.

Parameters
bufferpointer to buffer containing header
bufferLengthlength of buffer (must be at least BLOB_HEADER_SIZE bytes)
Returns
version number from the header
Exceptions
tenduke::crypto::CryptoExceptionif the header is invalid

◆ writeHeader()

virtual void tenduke::crypto::AbstractCiphers::writeHeader ( unsigned char * buffer,
std::uint16_t version ) const
inlineprotectedvirtual

Writes the blob header (magic and version) in network byte order.

Parameters
bufferpointer to buffer where the header will be written (must be at least BLOB_HEADER_SIZE bytes)
versionversion number to write

The documentation for this class was generated from the following file: