|
10Duke Enterprise C++ SDK
|
#include <AbstractCiphers.h>
Base class for cipher implementations using AES-256-GCM with PBKDF2 key derivation.
Implements VERSION_1 blob encryption and decryption using injected random and key-generator services. Subclasses supply the concrete service implementations via the constructor.
Output format (VERSION_1): [magic (4 bytes)] [version (2 bytes)] [nonce/salt (12 bytes)] [ciphertext] [tag (16 bytes)]
Public Member Functions | |
| AbstractCiphers (const std::shared_ptr<::tenduke::utl::random::RandomBytes > &random, const std::shared_ptr<::tenduke::crypto::PBKDF2 > &keyGenerator) | |
| std::unique_ptr<::tenduke::utl::BinaryData > | decrypt (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. | |
| std::unique_ptr<::tenduke::utl::BinaryData > | encrypt (const ::tenduke::utl::DataSpan &plaintext, const ::tenduke::utl::DataSpan &encryptionKey) const override |
| Encrypts given data using the system default cipher (AES256 GCM). | |
| std::unique_ptr<::tenduke::utl::BinaryData > | encrypt (const std::string &plaintext, const ::tenduke::utl::DataSpan &encryptionKey) const override |
| Encrypts given data using the system default cipher (AES256 GCM). | |
| std::string | decryptString (const ::tenduke::crypto::Cipher &cipher, const ::tenduke::utl::DataSpan &ciphertext) const override |
| Decrypts given data using the given cipher to a string. | |
| void | encrypt (const ::tenduke::crypto::Cipher &cipher, const ::tenduke::utl::DataSpan &plaintext, ::tenduke::utl::DataSink &ciphertext) const override |
| Encrypts data with the given cipher. | |
Protected Member Functions | |
| virtual std::unique_ptr<::tenduke::utl::BinaryData > | encryptBytes (const unsigned char *plaintext, std::size_t plaintextLength, const unsigned char *encryptionKey, std::size_t encryptionKeyLength) const |
| virtual std::unique_ptr<::tenduke::utl::BinaryData > | decryptBytes (const unsigned char *ciphertext, std::size_t ciphertextLength, const unsigned char *encryptionKey, std::size_t encryptionKeyLength) const |
| virtual void | writeHeader (unsigned char *buffer, const std::uint16_t version) const |
| virtual void | writeHeader (::tenduke::utl::DataSink &output, const std::uint16_t version) const |
| virtual std::uint16_t | readAndValidateHeader (const unsigned char *buffer, std::size_t bufferLength) const |
| virtual std::uint16_t | readAndValidateHeader (const ::tenduke::utl::DataSpan &buffer) const |
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). | |
| static constexpr std::uint16_t | VERSION_1 = 0x0001 |
| static constexpr std::uint16_t | VERSION_2 = 0x0002 |
| static constexpr int | PBKDF2_ITERATIONS = 100000 |
| Number of PBKDF2 iterations for VERSION_1 key derivation. | |
|
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.
| ciphertext | the cipher text (the data to decrypt), the maximum supported length is INT_MAX. |
| encryptionKey | encryption key |
Implements tenduke::crypto::Ciphers.
|
inlineoverridevirtual |
Decrypts given data using the given cipher to a string.
This method expects the input to consist of magic (4 bytes) + version (2 bytes) + encrypted content (which is specific to the cipher), i.e., the output produced by calling ::encrypt(cipher, plaintext, ciphertext).
| cipher | The initialized cipher used to decrypt the data. Must match with the cipher used to encrypt |
| ciphertext | the cipher text (the data to decrypt), the maximum supported length is INT_MAX. |
Implements tenduke::crypto::Ciphers.
|
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.
| ciphertext | the cipher text (the data to decrypt), the maximum supported length is INT_MAX. |
| encryptionKey | encryption key |
Implements tenduke::crypto::Ciphers.
|
inlineoverridevirtual |
Encrypts data with the given cipher.
The output consists of:
Implements tenduke::crypto::Ciphers.
|
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.
| plaintext | the plain text (the data to encrypt), the maximum supported length is INT_MAX. |
| encryptionKey | encryption key |
Implements tenduke::crypto::Ciphers.
|
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.
| plaintext | the plain text, the maximum supported length is INT_MAX. |
| encryptionKey | encryption key |
Implements tenduke::crypto::Ciphers.