Skip to content

AES Key Container

Overview

Is a container for a cryptographic key and AES cipher parameters.


Constructors

Default constructor

Constructs blank un-initialized instance of AES Key container.
Allows for a manual initialization, when needed.

AES::keyc()

  • Parameters:
Example
using namespace tancrypt

AES::keyc key;
key.setType(AES::Type::CBC256);
key.setKey(buffer);
key.setHashAlg(algorithm);

// Needs to be enabled manually if hashing used
key.setHashEnabled(true); 


Raw key

Warning

Please note that when constructing without key hashing, you're expected to provide a properly padded key of correct length. If you do not want to handle your key padding, use hashing by constructing with tancrypt::hashAlg.

Tip

To get a proper length for AES::Type you can use AES::RefKeylen(AES::Type type)

Constructs instance of AES Key container without key hashing.
When constructing without tancrypt::hashAlg, you must ensure your key data are pre-padded.

AES::keyc(const dutils::dbuffer& key,AES::Type type)

  • Parameters:
    • const dutils::dbuffer& key - Pre-padded key data
    • AES::Type type - Type of AES algorithm to use



Hashed key

Note

Bear in mind that to avoid possible race conditions and unnecessary state holding, the hashing occurs on encryption runtime this may cause this key constructor to be less efficient when encrypting more than once.

Constructs instance of AES Key container with key hashing. Key is automatically hashed on encryption using the given hash algorithm.

AES::keyc(const dutils::dbuffer& key,AES::Type type,tancrypt::hashAlg alg)

  • Parameters:
    • dutils::dbuffer key - Key data
    • tancrypt::AES::Type type - AES algorithm type
    • tancrypt::hashAlg alg - Hashing algorithm to use on key during encryption
  • Returns:
    • tancrypt::AES::keyc key


AES Type

Enum Constant Cryptographic Algorithm Mode Key Size
AES::Type::CBC128 AES-128-CBC CBC 128-bit
AES::Type::CBC192 AES-192-CBC CBC 192-bit
AES::Type::CBC256 AES-256-CBC CBC 256-bit
AES::Type::GCM128 AES-128-GCM GCM 128-bit
AES::Type::GCM192 AES-192-GCM GCM 192-bit
AES::Type::GCM256 AES-256-GCM GCM 256-bit



Methods

setType

Member method, sets type of AES algorithm.
Does not corrupt key and can be used even past first initialization.

AES::keyc::setType(AES::Type type)

  • Parameters:
    • AES::Type type - AES algorithm type


setHashAlg

Sets hashing algorithm to be used for key.
Does not corrupt key and can be used even past first initialization.

AES::keyc::setHashAlg(tancrypt::hashAlg alg)

  • Parameters:
    • tancrypt::hashAlg alg - Hashing algorithm of your choice


setKey

Member method, sets key data of the AES Key container.

AES::keyc::setKey(dutils::dbuffer key)

  • Parameters:
    • dutils::dbuffer key - Key data buffer




getHashAlg

Retrieves currently set hashing algorithm of the AES Key Container

AES::keyc::getHashAlg()

  • Parameters:
  • Returns:
    • tancrypt::hashAlg alg - Current hashing algorithm


getHashEnabled

Retrieves current bool state - is hasing enabled ? true/false

AES::keyc::getHashEnabled()

  • Parameters:
  • Returns:
    • bool hashingEnabled

getKey

Retrieves current key data buffer

AES::keyc::getKey()

  • Parameters:
  • Returns:
    • const dutils::dbuffer key