Qt 使用QuaZip库生成MD5加密Zip格式压缩文件
2017-10-05 23:12
816 查看
QuaZip库下载地址: https://sourceforge.net/projects/quazip/files/latest/download
#include "quazip.h"
#include "quazipfile.h"
#include "quazipfileinfo.h"
void uploadAnswerPackege()
{
// 压缩文件
//JlCompress::compressDir(QString("%1.zip").arg(GMethod::instance()->getAnswerName()), DIR_RESULT);
const QString& zipName(QString("%1.zip").arg(DIR_RESULT + GMethod::instance()->getZkzh()));
QuaZip zip(zipName);
if (!zip.open(QuaZip::mdCreate))
{
qDebug("Could not create zip: %s", qPrintable(zipName));
return;
}
const QString& innerName = QString("%1.ans").arg(GMethod::instance()->getZkzh());
QuaZipNewInfo newInfo(innerName);
//生成MD5加密
QByteArray byteArray;
byteArray.append(innerName);
QByteArray hash = QCryptographicHash::hash(byteArray, QCryptographicHash::Md5);
QString strMD5 = hash.toHex();
QuaZipFile file(&zip);
bool ret = file.open(QIODevice::WriteOnly,
newInfo, // QuaZipNewInfo结构体引用
strMD5.toUtf8().constData(), // 密码
0, // CRC值(默认值是0)
8); // 写入方法(0为文件夹,8为普通文件)
if (ret)
{
QFile file2(GMethod::instance()->getAnswerName());
bool isopen = file2.open(QIODevice::ReadOnly);
if (isopen)
{
// 开始写入文件的数据了
file.write(file2.readAll());
}
file2.close();
file.close();
}
zip.close();
ui->stackWidgetExam->setCurrentIndex(PAGE_END);
}
#include "quazip.h"
#include "quazipfile.h"
#include "quazipfileinfo.h"
void uploadAnswerPackege()
{
// 压缩文件
//JlCompress::compressDir(QString("%1.zip").arg(GMethod::instance()->getAnswerName()), DIR_RESULT);
const QString& zipName(QString("%1.zip").arg(DIR_RESULT + GMethod::instance()->getZkzh()));
QuaZip zip(zipName);
if (!zip.open(QuaZip::mdCreate))
{
qDebug("Could not create zip: %s", qPrintable(zipName));
return;
}
const QString& innerName = QString("%1.ans").arg(GMethod::instance()->getZkzh());
QuaZipNewInfo newInfo(innerName);
//生成MD5加密
QByteArray byteArray;
byteArray.append(innerName);
QByteArray hash = QCryptographicHash::hash(byteArray, QCryptographicHash::Md5);
QString strMD5 = hash.toHex();
QuaZipFile file(&zip);
bool ret = file.open(QIODevice::WriteOnly,
newInfo, // QuaZipNewInfo结构体引用
strMD5.toUtf8().constData(), // 密码
0, // CRC值(默认值是0)
8); // 写入方法(0为文件夹,8为普通文件)
if (ret)
{
QFile file2(GMethod::instance()->getAnswerName());
bool isopen = file2.open(QIODevice::ReadOnly);
if (isopen)
{
// 开始写入文件的数据了
file.write(file2.readAll());
}
file2.close();
file.close();
}
zip.close();
ui->stackWidgetExam->setCurrentIndex(PAGE_END);
}
相关文章推荐
- Qt使用QuaZIP 压缩/解压文件
- Qt使用QuaZip对文件进行压缩解压操作
- Qt使用QuaZip对文件进行压缩解压操作
- 使用C#压缩解压rar和zip格式文件
- 使用WinRar将Qt编译生成的exe和依赖的dll文件打包为一个exe文件的简单方法
- 使用QuaZip对文件进行压缩解压操作
- Qt使用post上传压缩文件
- qt的动态链接库生成、使用,还夹带一些pro文件的使用。
- Linux下如何解压rar、zip格式文件?Linux VPS安装7zip/使用方法/压缩解压中文文件名乱码解决方案
- Qt 静态库文件的生成使用!
- Qt中用QuaZip来压缩和解压缩文件
- 使用powershell批量添加Qt的文件(生成pro)
- Qt中用QuaZip来压缩和解压缩文件
- QT:直接使用ui文件生成h文件的方法
- 使用designer-qt3设计界面,生成对应.h和.cpp文件时遇到的问题
- 使用Qt生成PDF文件
- Qt中用QuaZip来压缩和解压缩文件
- 使用VS进行打包程序解决生成两个文件的问题(压缩后只有一个exe)
- Qt5.3里使用X264库将y4m文件进行压缩
- Qt使用自带的windeployqt 查找生成exe 必需的库文件