diff options
Diffstat (limited to 'src/crypt/cryptclassbase.h')
| -rw-r--r-- | src/crypt/cryptclassbase.h | 250 |
1 files changed, 250 insertions, 0 deletions
diff --git a/src/crypt/cryptclassbase.h b/src/crypt/cryptclassbase.h new file mode 100644 index 0000000..064264e --- /dev/null +++ b/src/crypt/cryptclassbase.h @@ -0,0 +1,250 @@ +#ifndef CRYPTCLASSBASE_H +#define CRYPTCLASSBASE_H + +#include <QString> +#include <QByteArray> + + + + +/** +* \class CryptClassBase +* \brief Purely virtual Base-Class for all Ciphers. +* +* This class serves as Base or Parent Class for all Ciphers, containing Methods to set or get key, encrypted (CryptText) and unencrypted (ClearText) text. +* The purely virtual Methods encrypt and decrypt have to be overloaded in each subclass. +* \author Uwe Gogolin [Gogolin.Uwe@FH-SWF.de] +* \version 0.1 +* \date 28.02.2013 +*/ +class CryptClassBase +{ +public: //Methods + /** + * \brief Class Constructor. + * + * Class Constructor. Does nothing. + */ + CryptClassBase(); + + /** + * \brief Class Destructor. + * + * Class Destructor. Overwrites Key, Crypt- and ClearText with 0 when called. + */ + ~CryptClassBase(); + + + + /** + * \brief Method to generate a random Key. + * + * Overload this if your Cipher supports/ needs random Key generation. + * \see CryptEngine::generateRandomKey + */ + virtual void generateRandomKey(); + + + /** + * \brief Method to set the Key for en/decryption. + * + * Sets the Attribute m_key to contents of value. + * \param QByteArray value Contains the Key to be used for en/decryption + * \see CryptEngine::setKey + */ + virtual void setKey( QByteArray value ); + + + /** + * \brief Method to set the Key for en/decryption. + * + * Sets the Attribute m_key to contents of value of length keyLength. + * \param const uchar* value Contains the Key to be used for en/decryption + * \param int keyLength Length of keyData contained in value + * \see CryptEngine::setKey + */ + virtual void setKey( const uchar* value, int keyLength ); + + + /** + * \brief Method to get the Key used for en/decryption. + * + * Returns a reference to the Attribute m_key, containing the current key for en/decryption. + * \returns QBteArray& key The Key used for en/decryption. + * \see Cryptengine::getKey + */ + virtual QByteArray& getKey() { return m_key; } + + + /** + * \brief Method to set the length of the Key used for en/decryption. + * + * Sets the length of the Key used for en/decryption to value. + * \see Cryptengine::setKeyLength + */ + virtual void setKeyLength( int value ) { m_keyLength = value; } + + + /** + * \brief Method to set the Initialization Vector for Ciphers needing it. + * + * Sets the Initialization Vector to contents of iv. + * \param const QBteArray& iv The Initialization Vector to contents of iv. + * \see Cryptengine::setIV + */ + virtual void setIV( const QByteArray& iv ) { m_iv = iv; } + + + /** + * \brief Method to get the Initialization Vector for Ciphers needing it. + * + * Returns a reference to the the Initialization Vector. + * \returns QBteArray& The Initialization Vector for Ciphers needing it. + * \see Cryptengine::getIV + */ + virtual QByteArray& getIV() { return m_iv; } + + /** + * \brief True if algorithm uses binary data instead of plain text. + * + * Binar Data cannot be displayed as Plain Text and vice versa. + * This property holds information on whether to handle the Crypted + * text prodiced by this class. + * \returns bool: True if algorithm uses binary data instead of plain text. + * \see CryptEngine::oncipherSelected_triggered() + */ + bool getBinaryData() { return m_binaryData; } + + + /** + * \brief Method to set the encrypted text. + * + * Sets the Attribute m_cryptText to contents of value. + * \param QByteArray value Contains the encrypted data + * \see CryptEngine::setCryptText + */ + void setCryptText( QByteArray value ); + + + /** + * \brief Method to set the encrypted text. + * + * Sets the Attribute m_cryptText to contents of value of length dataLength. + * \param const uchar* value Contains the encrypted data + * \param int dataLength Length of encrypted data contained in value + * \see CryptEngine::setCryptText + */ + void setCryptText( const uchar* value, int dataLength ); + + + /** + * \brief Method to set the unencrypted text. + * + * Sets the Attribute m_clearText to contents of value. + * \param QByteArray value Contains the unencrypted data + * \see CryptEngine::setClearText + */ + void setClearText( QByteArray value ); + + + /** + * \brief Method to set the unencrypted text. + * + * Sets the Attribute m_clearText to contents of value of length dataLength. + * \param const uchar* value Contains the unencrypted data + * \param int dataLength Length of unencrypted data contained in value + * \see CryptEngine::setClearText + */ + void setClearText( const uchar* value, int keyLength ); + + + /** + * \brief Method to get the encrypted text. + * + * Returns the encrypted data as a QByteArray + * \see CryptEngine::getCryptText + * \returns QByteArray with encrypted data + */ + QByteArray getCryptText() { return m_cryptText; } + + + /** + * \brief Method to get the unencrypted text. + * + * Returns the unencrypted data as a QByteArray + * \see CryptEngine::getClearText + * \returns QByteArray with unencrypted data + */ + QByteArray getClearText() { return m_clearText; } + + + /** + * \brief Purely virtual Method for encryption. + * + * SubClasses need to overload this purely virtual method so that it contains or calls all necessary steps to encrypt the data in + * m_clearText using the algorithm the specific SubClass is designed for. The encrypted Text will be stored in m_cryptText. + */ + virtual void encrypt() = 0; + + + /** + * \brief Purely virtual Method for decryption. + * + * SubClasses need to overload this purely virtual method so that it contains or calls all necessary steps to decrypt the data in + * m_cryptText using the algorithm the specific SubClass is designed for. The decrypted Text will be stored in m_clearText. + */ + virtual void decrypt() = 0; + + + +protected: //Attributes + /** + * \brief ByteArray to hold the Key for en/decryption. + * + * \attention Sensitive data. Overwrite when no longer needed! + */ + QByteArray m_key; + + + /** + * \brief Length of Key to use for the Cipher. + */ + int m_keyLength; + + + /** + * \brief ByteArray to hold the Initialization Vector for Ciphers needing it. + * + * \attention Sensitive data. Overwrite when no longer needed! + */ + QByteArray m_iv; + + + /** + * \brief ByteArray to hold the encrypted text. + * + * \attention Sensitive data. Overwrite when no longer needed! + */ + QByteArray m_cryptText; + + + /** + * \brief ByteArray to hold the unencrypted text. + * + * \attention Sensitive data. Overwrite when no longer needed! + */ + QByteArray m_clearText; + + + /** + * \brief True if algorithm uses binary data instead of plain text. + * + * Binar Data cannot be displayed as Plain Text and vice versa. + * This property holds information on whether to handle the Crypted + * text prodiced by this class. + * \see CryptEngine::oncipherSelected_triggered() + */ + bool m_binaryData; +}; + +#endif // CRYPTCLASSBASE_H |
