mirror of
https://github.com/QuasarApp/Qt-AES.git
synced 2025-05-06 10:19:33 +00:00
padding tests
This commit is contained in:
parent
1809de722f
commit
f94a6339de
@ -85,8 +85,7 @@ QByteArray QAESEncryption::getPadding(int currSize, int alignment)
|
||||
{
|
||||
QByteArray ret(0);
|
||||
int size = (alignment - currSize % alignment) % alignment;
|
||||
// if (size == 0)
|
||||
// size = alignment;
|
||||
if (size == 0) return ret;
|
||||
switch(m_padding)
|
||||
{
|
||||
case PADDING::ZERO:
|
||||
|
@ -29,9 +29,9 @@ public:
|
||||
static QByteArray Crypt(QAESEncryption::AES level, QAESEncryption::MODE mode, const QByteArray &rawText, const QByteArray &key, const QByteArray &iv = NULL);
|
||||
static QByteArray Decrypt(QAESEncryption::AES level, QAESEncryption::MODE mode, const QByteArray &rawText, const QByteArray &key, const QByteArray &iv = NULL);
|
||||
static QByteArray ExpandKey(QAESEncryption::AES level, QAESEncryption::MODE mode, const QByteArray &key);
|
||||
static QByteArray RemovePadding(const QByteArray &rawText, QAESEncryption::PADDING padding = PADDING::ZERO);
|
||||
static QByteArray RemovePadding(const QByteArray &rawText, QAESEncryption::PADDING padding = PADDING::ISO);
|
||||
|
||||
QAESEncryption(QAESEncryption::AES level, QAESEncryption::MODE mode, QAESEncryption::PADDING padding = QAESEncryption::ZERO);
|
||||
QAESEncryption(QAESEncryption::AES level, QAESEncryption::MODE mode, QAESEncryption::PADDING padding = QAESEncryption::ISO);
|
||||
|
||||
QByteArray encode(const QByteArray &rawText, const QByteArray &key, const QByteArray &iv = NULL);
|
||||
QByteArray decode(const QByteArray &rawText, const QByteArray &key, const QByteArray &iv = NULL);
|
||||
|
@ -62,43 +62,43 @@ void AesTest::ECB128Crypt()
|
||||
QCOMPARE(encryption.encode(in, key16), outECB128);
|
||||
}
|
||||
|
||||
//void AesTest::ECB128Decrypt()
|
||||
//{
|
||||
// QByteArray hexText, outputHex;
|
||||
// QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB);
|
||||
void AesTest::ECB128Decrypt()
|
||||
{
|
||||
QByteArray hexText, outputHex;
|
||||
QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB);
|
||||
|
||||
// QCOMPARE(QAESEncryption::RemovePadding(encryption.decode(outECB128, key16)), in);
|
||||
//}
|
||||
QCOMPARE(encryption.decode(outECB128, key16), in);
|
||||
}
|
||||
|
||||
//void AesTest::ECB192Crypt()
|
||||
//{
|
||||
// QByteArray outputHex;
|
||||
// QAESEncryption encryption(QAESEncryption::AES_192, QAESEncryption::ECB);
|
||||
void AesTest::ECB192Crypt()
|
||||
{
|
||||
QByteArray outputHex;
|
||||
QAESEncryption encryption(QAESEncryption::AES_192, QAESEncryption::ECB);
|
||||
|
||||
// QCOMPARE(QAESEncryption::RemovePadding(encryption.encode(in, key24)), outECB192);
|
||||
//}
|
||||
QCOMPARE(encryption.encode(in, key24), outECB192);
|
||||
}
|
||||
|
||||
//void AesTest::ECB192Decrypt()
|
||||
//{
|
||||
// QByteArray hexText;
|
||||
// QAESEncryption encryption(QAESEncryption::AES_192, QAESEncryption::ECB);
|
||||
void AesTest::ECB192Decrypt()
|
||||
{
|
||||
QByteArray hexText;
|
||||
QAESEncryption encryption(QAESEncryption::AES_192, QAESEncryption::ECB);
|
||||
|
||||
// QCOMPARE(QAESEncryption::RemovePadding(encryption.decode(outECB192, key24)), in);
|
||||
//}
|
||||
QCOMPARE(encryption.decode(outECB192, key24), in);
|
||||
}
|
||||
|
||||
//void AesTest::ECB256Crypt()
|
||||
//{
|
||||
// QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB);
|
||||
void AesTest::ECB256Crypt()
|
||||
{
|
||||
QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB);
|
||||
|
||||
// QCOMPARE(QAESEncryption::RemovePadding(encryption.encode(in, key32)), outECB256);
|
||||
//}
|
||||
QCOMPARE(encryption.encode(in, key32), outECB256);
|
||||
}
|
||||
|
||||
//void AesTest::ECB256Decrypt()
|
||||
//{
|
||||
// QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB);
|
||||
void AesTest::ECB256Decrypt()
|
||||
{
|
||||
QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB);
|
||||
|
||||
// QCOMPARE(QAESEncryption::RemovePadding(encryption.decode(outECB256, key32)), in);
|
||||
//}
|
||||
QCOMPARE(encryption.decode(outECB256, key32), in);
|
||||
}
|
||||
|
||||
void AesTest::ECB256String()
|
||||
{
|
||||
@ -120,19 +120,19 @@ void AesTest::ECB256String()
|
||||
|
||||
////==================CBC TESTING=========================
|
||||
|
||||
//void AesTest::CBC128Crypt()
|
||||
//{
|
||||
// QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::CBC);
|
||||
void AesTest::CBC128Crypt()
|
||||
{
|
||||
QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::CBC);
|
||||
|
||||
// QCOMPARE(QAESEncryption::RemovePadding(encryption.encode(inCBC128, key16, iv)), outCBC128);
|
||||
//}
|
||||
QCOMPARE(encryption.encode(inCBC128, key16, iv), outCBC128);
|
||||
}
|
||||
|
||||
//void AesTest::CBC128Decrypt()
|
||||
//{
|
||||
// QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::CBC);
|
||||
void AesTest::CBC128Decrypt()
|
||||
{
|
||||
QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::CBC);
|
||||
|
||||
// QCOMPARE(QString(QAESEncryption::RemovePadding(encryption.decode(outCBC128, key16, iv))), inCBC128);
|
||||
//}
|
||||
QCOMPARE(encryption.decode(outCBC128, key16, iv), inCBC128);
|
||||
}
|
||||
|
||||
//=================== CFB TESTING ============================
|
||||
|
||||
|
@ -12,18 +12,18 @@ private slots:
|
||||
void initTestCase();
|
||||
|
||||
void ECB128Crypt();
|
||||
// void ECB128Decrypt();
|
||||
void ECB128Decrypt();
|
||||
|
||||
// void ECB192Crypt();
|
||||
// void ECB192Decrypt();
|
||||
void ECB192Crypt();
|
||||
void ECB192Decrypt();
|
||||
|
||||
// void ECB256Crypt();
|
||||
// void ECB256Decrypt();
|
||||
void ECB256Crypt();
|
||||
void ECB256Decrypt();
|
||||
|
||||
void ECB256String();
|
||||
|
||||
// void CBC128Crypt();
|
||||
// void CBC128Decrypt();
|
||||
void CBC128Crypt();
|
||||
void CBC128Decrypt();
|
||||
|
||||
void CFB256String();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user