QT中使用AES_128长度密钥,CBC加密模式进行加密

先去github下载源码:

https://github.com/bricke/Qt-AES

 将下面两个文件放到项目中

如下图:

 

 加入头文件

#include "qaesencryption.h"

加密解密代码如下:

void MainWindow::on_pushButton_2_clicked()
{
    QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::CBC,QAESEncryption::PKCS7);

    QString key = "9876543219876543";
    QString iv = "1234567891234567";

    QString datad="hello world!";

    //加密
    QByteArray encoded = encryption.encode(datad.toLatin1(), key.toLatin1(),iv.toLatin1());
    QByteArray encodedBase64 = encoded.toBase64();
    //QString encodedBase64_text = QString::fromLatin1(encodedBase64);
    qDebug()<<"encode:"<<encodedBase64;

    //解密
    QByteArray decoded = encryption.decode(encoded, key.toLatin1(),iv.toLatin1());
    qDebug()<<"decode:"<<QString::fromLatin1(decoded);
}

问题:我修改了AES_128为AES_192以及AES_256,也把key密钥改成了对应的长度,但是加密出来的数据为空,没有找到原因,如果有知道的小伙伴希望告知!!!

猜你喜欢

转载自blog.csdn.net/m0_67254672/article/details/132433618
今日推荐