|
| 1 | +#include <QCoreApplication> |
| 2 | +#include <QFile> |
| 3 | +#include <QDebug> |
| 4 | +#include "nencryptionkit.h" |
| 5 | + |
| 6 | +int main(int argc, char *argv[]) |
| 7 | +{ |
| 8 | + QCoreApplication a(argc, argv); |
| 9 | + qDebug()<<"******************************************测试用例开始*****************************************************"; |
| 10 | + NEncryptionKit test_instance; |
| 11 | + qDebug()<<"----------------------------MD5测试开始----------------------------"; |
| 12 | + QString test_case_001("I am daodaoliang"); |
| 13 | + QString test_encry_str = test_instance.getMD5Hash(test_case_001); |
| 14 | + qDebug()<<"MD5前的字符串:" << test_case_001; |
| 15 | + qDebug()<<"MD5后的字符串:" << test_encry_str; |
| 16 | + qDebug()<<"----------------------------MD5测试结束----------------------------"; |
| 17 | + |
| 18 | + qDebug()<<"----------------------------SHA测试开始----------------------------"; |
| 19 | + QString test_case_002("I am nami"); |
| 20 | + QString test_encry_str_002 = test_instance.getSHAHash(test_case_002); |
| 21 | + qDebug()<<"SHA前的字符串:" << test_case_002; |
| 22 | + qDebug()<<"SHA后的字符串:" << test_encry_str_002; |
| 23 | + qDebug()<<"----------------------------SHA测试结束----------------------------"; |
| 24 | + |
| 25 | + qDebug()<<"----------------------------Kaiser测试开始-------------------------"; |
| 26 | + QString test_case_003("I am wangxiaowei"); |
| 27 | + qint8 test_case_key(7); |
| 28 | + QString test_encry_str_003 = test_case_003; |
| 29 | + bool ret = test_instance.getByKaiser(test_case_003, test_case_key); |
| 30 | + qDebug()<<"加密是否成功:"<<ret; |
| 31 | + qDebug()<<"Kaiser前的字符串:" << test_encry_str_003; |
| 32 | + qDebug()<<"Kaiser后的字符串:" << test_case_003; |
| 33 | + ret = test_instance.getByKaiser(test_case_003, -test_case_key); |
| 34 | + qDebug()<<"解密是否成功:"<<ret; |
| 35 | + qDebug()<<"解密后的字符串:" << test_case_003; |
| 36 | + qDebug()<<"----------------------------Kaiser测试结束-------------------------"; |
| 37 | + |
| 38 | + qDebug()<<"----------------------------AES文件测试开始-------------------------"; |
| 39 | + QString test_case_005("iamdaodaoliang"); |
| 40 | + string test_case_006; |
| 41 | + QString test_case_007; |
| 42 | + test_instance.setPassword(QString("IamdaodaoliangSecret")); |
| 43 | + ret = test_instance.getEncryByAES(test_case_005,test_case_006); |
| 44 | + qDebug()<<"AES加密成功:"<<ret; |
| 45 | + qDebug()<<"加密前的数据:"<<test_case_005; |
| 46 | + qDebug()<<"加密后的数据:"<<QString::fromStdString(test_case_006); |
| 47 | + ret = test_instance.decryptByAES(test_case_006,test_case_007); |
| 48 | + qDebug()<<"AES解密成功:"<<ret; |
| 49 | + qDebug()<<"解密后的数据:"<<test_case_007; |
| 50 | + qDebug()<<"----------------------------AES文件测试结束-------------------------"; |
| 51 | + |
| 52 | + qDebug()<<"----------------------------RSA文件测试开始-------------------------"; |
| 53 | + QString test_case_pub = QCoreApplication::applicationDirPath() + "/daodaoliang_test.pub"; |
| 54 | + QString test_case_pri = QCoreApplication::applicationDirPath() + "/daodaoliang_test.private"; |
| 55 | + ret = test_instance.createRSAKey(test_case_pub, test_case_pri); |
| 56 | + qDebug()<<"是否产生密钥文件成功:"<<ret; |
| 57 | + QByteArray test_encrypt_str; |
| 58 | + QString test_decrypt_str; |
| 59 | + ret = test_instance.getEncryptByRSA("I am daodaoliang, my daughter is nami", test_encrypt_str, test_case_pub); |
| 60 | + qDebug()<<"RSA签名成功:"<<ret; |
| 61 | + qDebug()<<"RSA签名后的数据:"<<QString(test_encrypt_str); |
| 62 | + ret = test_instance.decryptionByRSA(test_encrypt_str,test_decrypt_str, test_case_pri); |
| 63 | + qDebug()<<"RSA解密成功:"<<ret; |
| 64 | + qDebug()<<"RSA解密后的数据:"<<test_decrypt_str; |
| 65 | + qDebug()<<"----------------------------RSA文件测试结束-------------------------"; |
| 66 | + |
| 67 | + qDebug()<<"******************************************测试用例结束*****************************************************"; |
| 68 | + return a.exec(); |
| 69 | +} |
0 commit comments