blob: 92721833375b170214129952ab7a19996eee1ffb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
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
|