mirror of
https://github.com/QuasarApp/Qt-Secret.git
synced 2025-05-02 02:19:33 +00:00
added simple test for aes
This commit is contained in:
parent
9696234a14
commit
39d4bf4d0e
4
test.pri
4
test.pri
@ -5,8 +5,8 @@
|
||||
# of this license document, but changing it is not allowed.
|
||||
#
|
||||
|
||||
unix:exec = $$PWD/src/mini-gmp/tests/build/release/QtBigIntTests,$$PWD/tests/build/release/Qt-SecretTest,$$PWD/src/Qt-AES/build/release/QAESEncryption
|
||||
win32:exec = $$PWD/src/mini-gmp/tests/build/release/QtBigIntTests.exe,$$PWD/src/Qt-AES/build/release/QAESEncryption.exe,$$PWD/tests/build/release/Qt-SecretTest.exe
|
||||
unix:exec = $$PWD/src/mini-gmp/tests/build/release/QtBigIntTests,$$PWD/tests/build/release/Qt-SecretTest
|
||||
win32:exec = $$PWD/src/mini-gmp/tests/build/release/QtBigIntTests.exe,$$PWD/tests/build/release/Qt-SecretTest.exe
|
||||
|
||||
QT_DIR = $$[QT_HOST_BINS]
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include <cmath>
|
||||
#include <time.h>
|
||||
#include <iostream>
|
||||
#include <QCryptographicHash>
|
||||
#include "qaesencryption.h"
|
||||
|
||||
//const int testSize = 20;
|
||||
static const QMap<QRSAEncryption::Rsa, int > testSize = {
|
||||
@ -213,6 +215,33 @@ bool testEncryptAndDecryptExample() {
|
||||
return decodeMessage == msg;
|
||||
}
|
||||
|
||||
bool testEncryptAndDecryptAESExample() {
|
||||
|
||||
print("Begin test AES alghoritms");
|
||||
|
||||
QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::CBC);
|
||||
|
||||
QString inputStr("The Advanced Encryption Standard (AES), also known by its original name Rijndael "
|
||||
"is a specification for the encryption of electronic data established by the U.S. "
|
||||
"National Institute of Standards and Technology (NIST) in 2001");
|
||||
QString key("your-string-key");
|
||||
QString iv("your-IV-vector");
|
||||
|
||||
QByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(), QCryptographicHash::Sha256);
|
||||
QByteArray hashIV = QCryptographicHash::hash(iv.toLocal8Bit(), QCryptographicHash::Md5);
|
||||
|
||||
QByteArray encodeText = encryption.encode(inputStr.toLocal8Bit(), hashKey, hashIV);
|
||||
QByteArray decodeText = encryption.decode(encodeText, hashKey, hashIV);
|
||||
|
||||
QString decodedString = QString(encryption.removePadding(decodeText));
|
||||
|
||||
if (decodedString != inputStr)
|
||||
return false;
|
||||
|
||||
print("AES test finished successful");
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
if (!testGetKeyRsaType()) {
|
||||
@ -227,6 +256,10 @@ int main() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!testEncryptAndDecryptAESExample()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (auto testCase = testSize.begin(); testCase != testSize.end(); ++testCase) {
|
||||
if(!testCrypto(testCase.key())) {
|
||||
return 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user