Qt AES 加密解密


一、

使用庫:https://github.com/bricke/Qt-AES

二、代碼舉例

#include <QCryptographicHash>
void MainWindow::on_pushButton_clicked()
{
    QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB, QAESEncryption::ZERO);

    QString key="12345";
    QString date="20200730";
    QString data="BFEBFBFF000406F1Z9ABXEMP"+date;

    QByteArray hashKey = QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Md5);
    QByteArray encodedText = encryption.encode(data.toUtf8(), hashKey);
    QString str_encode_text=QString::fromLatin1(encodedText.toBase64());
    qDebug()<<"encodedText:"<<str_encode_text;



    //QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB, QAESEncryption::ZERO);
    QByteArray hashKey2 = QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Md5);
    QByteArray decodedText = encryption.decode(QByteArray::fromBase64(str_encode_text.toLatin1()), hashKey2);
    qDebug()<<"decodedText:"<<QString::fromLatin1(decodedText);
    
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM