-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.cpp
103 lines (69 loc) · 2.9 KB
/
utilities.cpp
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
#include "utilities.h"
#include <QString>
#include <QDateTime>
#include <QCryptographicHash>
#include "AESLibrary/qaesencryption.h"
#include <QDebug>
#include "emailLibrary/SmtpMime"
utilities::utilities()
{
}
QByteArray utilities::encrypt(QString str){
QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::CBC,QAESEncryption::ZERO);
QString key = "RgUkXp2s5v8y/B?E(H+MbQeThVmYq3t6";
QString iv = "9y$B&E)H@McQfTjWnZq4t7w!z%C*F-Ja";
QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256);
QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5);
QByteArray encodeText = encryption.encode(str.toLocal8Bit(), hashKey, hashIV);
return encodeText;
}
QString utilities::decrypt(QByteArray str){
QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::CBC,QAESEncryption::ZERO);
QString key = "RgUkXp2s5v8y/B?E(H+MbQeThVmYq3t6";
QString iv = "9y$B&E)H@McQfTjWnZq4t7w!z%C*F-Ja";
QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256);
QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5);
QByteArray decodeText = encryption.decode(str, hashKey, hashIV);
char fixed[2048];
int index = 0;
QByteArray::iterator iter = decodeText.begin();
while(iter != decodeText.end())
{
QChar c = *iter;
if (c != '\0') fixed[index++] = c.toLatin1();
iter++;
}
fixed[index] = '\0';
return decodeText;
}
QString utilities::getDataAndTime()
{
QDateTime date = QDateTime::currentDateTime();
QString formattedTime = date.toString("hh:mm:ss | yyyy.MM.dd");
QByteArray formattedTimeMsg = formattedTime.toLocal8Bit();
return formattedTimeMsg;
}
bool utilities::sendMail()
{
SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
// We need to set the username (your email address) and the password
// for smtp authentification.
smtp.setUser("[email protected]");
smtp.setPassword("252517994005");
// Now we create a MimeMessage object. This will be the email.
MimeMessage message;
message.setSender(new EmailAddress("[email protected]", "Ali Kazemi"));
message.addRecipient(new EmailAddress("[email protected]", "Majid Kazemi"));
message.setSubject("SmtpClient for Qt - Demo");
// Now add some text to the email.
// First we create a MimeText object.
MimeText text;
text.setText("Hi,\nThis is a simple email message.\n");
// Now add it to the mail
message.addPart(&text);
// Now we can send the mail
smtp.connectToHost();
smtp.login();
smtp.sendMail(message);
smtp.quit();
}