diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-03-25 10:15:50 +0100 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-03-25 10:33:32 +0100 |
| commit | a1e3d36dca9c6abf235c7ddf47ab9185c4b748d5 (patch) | |
| tree | 859befb5df101432b7388e1562f90a01c6d8e238 /src/crypt/cryptengine.h | |
| download | IT-Sicherheit-a1e3d36dca9c6abf235c7ddf47ab9185c4b748d5.tar.gz IT-Sicherheit-a1e3d36dca9c6abf235c7ddf47ab9185c4b748d5.zip | |
First commit of IT-Sicherheit
Diffstat (limited to 'src/crypt/cryptengine.h')
| -rw-r--r-- | src/crypt/cryptengine.h | 261 |
1 files changed, 261 insertions, 0 deletions
diff --git a/src/crypt/cryptengine.h b/src/crypt/cryptengine.h new file mode 100644 index 0000000..9272183 --- /dev/null +++ b/src/crypt/cryptengine.h @@ -0,0 +1,261 @@ +#ifndef CRYPTENGINE_H +#define CRYPTENGINE_H + +#include <QObject> + +#include "../cipherssingleton.h" +#include "cryptclassbase.h" +#include "cryptclassnullcipher.h" +//#include "cryptclasscaesar.h" +//#include "cryptclasscube.h" +//#include "cryptclassaes.h" +//#include "cryptclassrsa.h" +//#include "cryptclassecc.h" + + +/** +* \class CryptEngine +* \brief Interface for all algorithms. +* +* This class provides an easy to use interface for all Ciphers/algorithms (used as synonyms) and encapsulates all functionality +* related to de/encryption. +* Ciphers are referenced by NameSpaceCryptEngine::CryptAlgorithm (see enums.h), the currently active one stored in m_algorithm. +* The Functionality for every Cipher is encapsulated in a SubClass of CryptClassBase, m_cryptClass points to an instance of the +* one for the currently active algorithm. +* \author Uwe Gogolin [Gogolin.Uwe@FH-SWF.de] +* \version 0.7 +* \date 13.05.2013 +*/ +class CryptEngine : public QObject +{ + Q_OBJECT + +public: //Methods + /** + * \brief Class Constructor. + * + * Class Constructor. Initializes NullCipher. + * \param QObject* parent The QObject the used instance of this class is subordinated to. + */ + CryptEngine( QObject* parent = 0 ); + + + /** + * \brief Class Destructor. + * + * Class Destructor. Overwrites Key, Crypt- and ClearText with 0 when called. + */ + ~CryptEngine(); + + + + /** + * \brief Method to generate a random Key. + * + * Calls Method generateKey of the CryptClass in use. + * \attention This Method may do nothing depending on the Algorithm in use. + * \see CryptClassBase::generateRandomKey + */ + void generateRandomKey(); + + + /** + * \brief Method to set the Key for en/decryption. + * + * Sets the Attribute m_key to contents of value. + * \param QString value Contains the Key to be used for en/decryption + * \see CryptClassBase::setKey + */ + void setKey( QString value ); + + + /** + * \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 CryptClassBase::setKey + */ + 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 CryptClassBase::setKey + */ + 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 CryptClassBase::getKey + */ + QByteArray& getKey(); + + + /** + * \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 CryptClassBase::setKeyLength + */ + virtual void setKeyLength( int value ) { m_cryptClass->setKeyLength(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 CryptClassBase::setIV + */ + virtual void setIV( const QByteArray& iv ) { m_cryptClass->setIV(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 CryptClassBase::getIV + */ + virtual QByteArray& getIV() { return m_cryptClass->getIV(); } + + + /** + * \brief Method to set the encrypted text. + * + * Sets the Attribute m_cryptText to contents of value. + * \param QByteArray value Contains the encrypted data + * \see CryptClassBase::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 CryptClassBase::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 CryptClassBase::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 CryptClassBase::setClearText + */ + void setClearText( const uchar* value, int keyLength ); + + + /** + * \brief Method to get the encrypted text. + * + * Returns the encrypted data as a QByteArray + * \see CryptClassBase::getCryptText + * \returns QByteArray with encrypted data + */ + QByteArray getCryptText() { return m_cryptClass->getCryptText(); } + + + /** + * \brief Method to get the unencrypted text. + * + * Returns the unencrypted data as a QByteArray + * \see CryptClassBase::getClearText + * \returns QByteArray with unencrypted data + */ + QByteArray getClearText() { return m_cryptClass->getClearText(); } + + + /** + * \brief Method to encrypt present unencrypted data using the currently selected algorithm and key. + * + * Calls the encrypt method of the currently selected algorithm + */ + void encrypt(); + + + /** + * \brief Method to decrypt present encrypted data using the currently selected algorithm and key. + * + * Calls the decrypt method of the currently selected algorithm + */ + void decrypt(); + + + +public slots: + /** + * \brief Slot called when an active algorithm gets selected. + * + * Deletes intance of former Cipher and creates a new object for the selected one. + * \param int cipher Integer referencing the selected Cipher according to assignment in Class CiphersSingleton. + * \see Class CiphersSingleton + */ + void oncipherSelected_triggered( int cipher ); + + + /** + * \brief SLOT to set the new Keylength. + * + * Called when a new Keylength is selected. Passes the value on in connection with the bool + * signifying that it is for a symmetric Cipher (true) or an asymmetric one (false). + * \param int value The new Keylength. + * \param bool symmetric true for symmetric Cipher, false for asymmetric. + */ + void onkeylengthChanged(int value, bool symmetric); + + +signals: + /** + * \brief SIGNAL to inform other Classes that the selected Cipher uses binary data. + * + * This Signal is used to inform other Classes that the selected Cipher uses binary data. + * \param bool dataIsbinary is true when data should be displayes as Hex. + */ + void binaryData( bool dataIsBinary ); + + +private: //Attributes + /** + * \brief Enum for currently used algorithm (NullCipher/ Caesar). + * + * \see File enums.h for list of available algorithms + */ + int m_algorithm; + + + /** + * \brief Pointer to an instance of a SubClass of CryptclassBase for the currently used algorithm. + * + * Should either be NULL or point to an instance of the SubClass for the algorithm specified in m_algorithm + * \see CryptClassBase + */ + CryptClassBase* m_cryptClass; +}; + +#endif // CRYPTENGINE_H |
