求助:如何用LZMA进行加密打包、文件名加密,相关函数是哪个?例如:创建压缩包、将文件添加到压缩包等方面的函数
问题详述:
前阶段我写的小工具需要用到文件打包压缩的功能,原来已有的zip源代码可以实现打包压缩,但是无法做到文件名加密等拓展功能,知道7z比我有的zip功能更强大,后来在7z的网站(http://sparanoid.com/lab/7z/)上下载了源代码LZMA SDK。
解压后发现,一大堆代码,根据网上常见的代码,我知道单个文件压缩的函数。
以下是压缩单个文件的代码:
#include <stdio.h>
#include <tchar.h>
#include <Types.h>
#include <LzmaLib.h>
#pragma comment(lib, "7z lib comprile.lib")
int _tmain(int argc, _TCHAR* argv[])
{
FILE *pFile;
_tfopen_s(&pFile,_T("1.pdf"),_T("rb"));
if (pFile == NULL)
{
_ftprintf_s(stderr,_T("Error to Open the file!"));
return -1;
}
fseek(pFile,0,SEEK_END);
size_t srcLen = ftell(pFile);
rewind(pFile);
size_t destLen = srcLen*2;
unsigned char *psrcRead = new unsigned char[srcLen]; //原始文件数据
unsigned char *pDecomress = new unsigned char[srcLen]; //存放解压缩数据
unsigned char *pLzma = new unsigned char[destLen]; //存放压缩数据
fread(psrcRead,sizeof(char),srcLen,pFile);
unsigned char prop[5];
size_t sizeProp = 5;
if (SZ_OK != LzmaCompress(pLzma,&destLen,psrcRead,srcLen,prop,&sizeProp,5,(1<<24),3,0,2,32,2))
{//出错了
_ftprintf_s(stderr,_T("压缩时出错!"));
delete psrcRead;
delete pDecomress;
delete pLzma;
fclose(pFile);
return -1;
}
FILE *pCompressFile;
_tfopen_s(&pCompressFile,_T("compress.dat"),_T("wb")); //写入压缩后的数据
if (pCompressFile == NULL)
{
_ftprintf_s(stderr,_T("创建文件出错!"));
delete psrcRead;
delete pDecomress;
delete pLzma;
fclose(pFile);
return -1;
}
fwrite(pLzma,sizeof(char),destLen,pCompressFile);
fclose(pCompressFile);
FILE *pDecompressFile;
_tfopen_s(&pDecompressFile,_T("decompress.dat"),_T("wb")); //写入解压缩数据
if (pDecompressFile == NULL)
{
_ftprintf_s(stderr,_T("写入数据出错!"));
delete psrcRead;
delete pDecomress;
delete pLzma;
fclose(pFile);
return -1;
}
if (SZ_OK != LzmaUncompress(pDecomress,&srcLen,pLzma,&destLen,prop,5))
{
delete psrcRead;
delete pDecomress;
delete pLzma;
fclose(pDecompressFile);
fclose(pFile);
return -1;
}
fwrite(pDecomress,sizeof(char),srcLen,pDecompressFile);
delete psrcRead;
delete pDecomress;
delete pLzma;
fclose(pDecompressFile);
fclose(pFile);
return 0;
}
但是我想知道关于创建压缩包、文件添加到压缩包、文件名加密等方面的函数在哪里,望有相关经验的大牛指点指点!
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课