blob: ed02d8566a60c05f220425a539c46ab9ed27326d (
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
|
#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.
*/
virtual ~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
|