Rudiments
Public Member Functions | List of all members
encryption Class Referenceabstract

Inherits object.

Inherited by aes128.

Public Member Functions

 encryption ()
 
virtual ~encryption ()
 
virtual bool setKey (const byte_t *key, size_t keysize)
 
virtual void setRandomKey ()
 
virtual byte_t * getKey ()
 
virtual size_t getKeySize ()=0
 
virtual bool setIv (const byte_t *iv, size_t ivsize)
 
virtual void setRandomIv ()
 
virtual byte_t * getIv ()
 
virtual size_t getIvSize ()=0
 
virtual bool append (const byte_t *data, uint32_t size)
 
virtual const byte_t * getEncryptedData ()=0
 
virtual uint64_t getEncryptedDataSize ()
 
virtual const byte_t * getDecryptedData ()=0
 
virtual uint64_t getDecryptedDataSize ()
 
virtual encryptionerror_t getError ()
 
virtual bool clear ()
 
virtual bool reset ()
 
- Public Member Functions inherited from object
virtual ~object ()
 

Detailed Description

The encryption class provides a simple encryption interface.

Constructor & Destructor Documentation

◆ encryption()

encryption::encryption ( )

Creates an instance of the encryption class.

◆ ~encryption()

virtual encryption::~encryption ( )
virtual

Deletes this instance of the encryption class.

Member Function Documentation

◆ append()

virtual bool encryption::append ( const byte_t *  data,
uint32_t  size 
)
virtual

Appends "size" bytes of "data" to the data to be encrypted/decrypted.

Returns true on success or false if an error occurred.

◆ clear()

virtual bool encryption::clear ( )
virtual

Clears the current encrypted/decrypted data and any data that had been appended.

Does not clear the key or initialization vector.

This implementation always returns true, but a child class may override this method to return false if something fails, and possibly set an error.

◆ getDecryptedData()

virtual const byte_t* encryption::getDecryptedData ( )
pure virtual

Interprets the current data as encrypted. Decrypts the current data.

Returns the decrypted data on success or NULL if an error occurred.

Note that the decrypted data returned will be an empty string if no data has been appended yet.

Implemented in aes128.

◆ getDecryptedDataSize()

virtual uint64_t encryption::getDecryptedDataSize ( )
virtual

Returns the number of bytes of decrypted data.

◆ getEncryptedData()

virtual const byte_t* encryption::getEncryptedData ( )
pure virtual

Interprets the current data as unencrypted. Encrypts the current data.

Returns the encrypted data on success or NULL if an error occurred.

Note that the encrypted data returned will be an empty string if no data has been appended yet.

Implemented in aes128.

◆ getEncryptedDataSize()

virtual uint64_t encryption::getEncryptedDataSize ( )
virtual

Returns the number of bytes of encrypted data.

◆ getError()

virtual encryptionerror_t encryption::getError ( )
virtual

Returns the most recent error.

◆ getIv()

virtual byte_t* encryption::getIv ( )
virtual

Returns the initialization vector currently used for encryption/decryption. If no initialization vector has been set, then this will be a block of 0's.

◆ getIvSize()

virtual size_t encryption::getIvSize ( )
pure virtual

Returns the number of bytes in the initialization vector.

Implemented in aes128.

◆ getKey()

virtual byte_t* encryption::getKey ( )
virtual

Returns the key currently used for encryption/decryption. If no key has been set, then this will be a block of 0's.

◆ getKeySize()

virtual size_t encryption::getKeySize ( )
pure virtual

Returns the number of bytes in the key.

Implemented in aes128.

◆ reset()

virtual bool encryption::reset ( )
virtual

Clears the current encrypted/decrypted data, any data that had been appended, any current error, key, and initialization vector.

This implementation always returns true, but a child class may override this method to return false if something fails, and possibly set an error.

◆ setIv()

virtual bool encryption::setIv ( const byte_t *  iv,
size_t  ivsize 
)
virtual

Sets the initialization vector used for encryption/decryption to the first "ivsize" bytes of "iv".

Returns true on success and false if an error occurred.

The most common error is that "ivsize" is not the correct number of bytes. The method getKeySize() returns the correct number of bytes for the key.

◆ setKey()

virtual bool encryption::setKey ( const byte_t *  key,
size_t  keysize 
)
virtual

Sets the key used for encryption/decryption to the first "keysize" bytes of "key".

Returns true on success and false if an error occurred.

The most common error is that "keysize" is not the correct number of bytes. The method getKeySize() returns the correct number of bytes for the key.

◆ setRandomIv()

virtual void encryption::setRandomIv ( )
virtual

Sets the initialization vector used encryption/decryption to random data. The data used can be retrived using getKey().

◆ setRandomKey()

virtual void encryption::setRandomKey ( )
virtual

Sets the key used for encryption/decryption to random data. The data used can be retrived using getKey().