一、
1.第三方库
https://gitcode.net/mirrors/bricke/Qt-AES?utm_source=csdn_github_accelerator
2.考本相关文件
3.添加到项目里
二、
void MainWindow::on_pushButton_clicked() { //key长度为16字节,就要选择AES_128,因为16*8=128,key长度必须为16字节 QString key = "0123456789012345"; qDebug() << "key.size : " << key.toUtf8().size(); QString str = "Hello World"; QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB, QAESEncryption::PKCS7); QByteArray enBA = encryption.encode(str.toUtf8(), key.toUtf8()); //QByteArray enBABase64 = enBA.toBase64(); QString encrypt_str = enBA.toBase64(); qDebug()<<"加密:"<< encrypt_str; enBA = QByteArray::fromBase64(encrypt_str.toUtf8()); QByteArray deBA = encryption.decode(enBA,key.toUtf8()); QString decrypt_str = QAESEncryption::RemovePadding(deBA,QAESEncryption::PKCS7); qDebug()<<"解密:"<<decrypt_str; if(str == decrypt_str) { qDebug()<<"加密解密成功" ; } else { qDebug()<<"加密解密失败" ; } }
标签:AES,字节,16,key,128,Qt From: https://www.cnblogs.com/ike_li/p/17463096.html