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
|
#include "cryptengine.h"
CryptEngine::CryptEngine(QObject *parent)
: QObject(parent)
{
m_algorithm = 0; //Initialize NullCipher
m_cryptClass = new CryptClassNullCipher;
}
CryptEngine::~CryptEngine()
{
delete m_cryptClass;
}
void CryptEngine::generateRandomKey()
{
m_cryptClass->generateRandomKey();
}
void CryptEngine::setKey(QString value)
{
m_cryptClass->setKey( value.toLatin1() );
}
void CryptEngine::setKey(QByteArray value)
{
m_cryptClass->setKey( value );
}
void CryptEngine::setKey(const uchar *value, int keyLength )
{
m_cryptClass->setKey( value, keyLength );
}
QByteArray &CryptEngine::getKey()
{
return m_cryptClass->getKey();
}
void CryptEngine::setCryptText(QByteArray value)
{
m_cryptClass->setCryptText(value);
}
void CryptEngine::setCryptText(const uchar *value, int dataLength )
{
m_cryptClass->setCryptText(value, dataLength);
}
void CryptEngine::setClearText(QByteArray value)
{
m_cryptClass->setClearText(value);
}
void CryptEngine::setClearText(const uchar *value, int dataLength )
{
m_cryptClass->setClearText(value, dataLength);
}
void CryptEngine::encrypt()
{
//If cleartext present, set in CryptClass, encrypt, and fetch encrypted data
if( m_cryptClass->getClearText().length() > 0 )
{
m_cryptClass->encrypt();
}
}
void CryptEngine::decrypt()
{
//If crypttext present, set in CryptClass, decrypt, and fetch decrypted data
if( m_cryptClass->getCryptText().length() > 0 )
{
m_cryptClass->decrypt();
}
}
void CryptEngine::oncipherSelected_triggered(int cipher)
{
m_algorithm = cipher;
//Get Instance of Singleton mapping Integers to String for Cipher description
CiphersSingleton ciphers = CiphersSingleton::getInstance();
//Algorithm contains cipher as text.
QString algorithm = ciphers.textFromValue(m_algorithm);
//delete old CryptClass and create new one according to selected algorithm
if( algorithm == "NullCipher" )
{
delete m_cryptClass;
m_cryptClass = new CryptClassNullCipher;
qDebug("CryptEngine::oncipherSelected_triggered - NullCipher");
}
else if( algorithm == "Caesar" )
{
delete m_cryptClass;
m_cryptClass = new CryptClassCaesar;
qDebug("CryptEngine::oncipherSelected_triggered - Caesar");
}
else if( algorithm == "RC4" )
{
delete m_cryptClass;
m_cryptClass = new CryptClassRc4;
qDebug("CryptEngine::oncipherSelected_triggered - RC4");
}
else if( algorithm == "Cube" )
{
// delete m_cryptClass;
// m_cryptClass = new CryptClassCube;
qDebug("CryptEngine::oncipherSelected_triggered - Cube");
}
else if( algorithm == "AES" )
{
delete m_cryptClass;
m_cryptClass = new CryptAes;
qDebug("CryptEngine::oncipherSelected_triggered - AES");
}
else if( algorithm == "RSA" )
{
// delete m_cryptClass;
// m_cryptClass = new CryptClassRSA;
qDebug("CryptEngine::oncipherSelected_triggered - RSA");
}
else if( algorithm == "ECC" )
{
// delete m_cryptClass;
// m_cryptClass = new CryptClassECC;
qDebug("CryptEngine::oncipherSelected_triggered - ECC");
}
//Send Signal confirming if data is binary or not
emit binaryData( m_cryptClass->getBinaryData() );
}
void CryptEngine::onkeylengthChanged(int value, bool symmetric)
{
qDebug("CrptEngine::onkeylengthChanged - new Keylength: %d", value);
m_cryptClass->setKeyLength(value);
}
|