2 Star 64 Fork 14

richards/Qt AES

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.cpp 2.91 KB
一键复制 编辑 原始数据 按行查看 历史
richards 提交于 2018-09-25 10:48 . fork 并修改 用以支持vs2013
#include <QCoreApplication>
#include <QCryptographicHash>
#include <QDebug>
#include "qaesencryption.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
{
QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB , QAESEncryption::ISO);
QByteArray input("HELLO AES");
QByteArray key = QString("your-string-key").toLocal8Bit();
QByteArray encodedText = encryption.encode(input, key);
QByteArray decodedText = encryption.decode(encodedText, key);
QString decodedString = QString(QAESEncryption::RemovePadding(decodedText,QAESEncryption::ISO));
qDebug() << decodedString;
}
{
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);
//Static invocation
QByteArray encodeText = QAESEncryption::Crypt(QAESEncryption::AES_256, QAESEncryption::CBC,
inputStr.toLocal8Bit(), hashKey, hashIV);
QByteArray decodeText = QAESEncryption::Decrypt(QAESEncryption::AES_256,QAESEncryption::CBC,encodeText, hashKey, hashIV);
// Removal of Padding via Static function
QString decodedString = QString(QAESEncryption::RemovePadding(decodeText,QAESEncryption::ISO));
qDebug() << decodedString;
}
/****************************************************************************************************/
{
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));
qDebug() << decodedString;
}
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/BlueBuger/Qt-AES.git
[email protected]:BlueBuger/Qt-AES.git
BlueBuger
Qt-AES
Qt AES
master

搜索帮助