本文整理汇总了C++中DES::Des_Go方法的典型用法代码示例。如果您正苦于以下问题:C++ DES::Des_Go方法的具体用法?C++ DES::Des_Go怎么用?C++ DES::Des_Go使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DES
的用法示例。
在下文中一共展示了DES::Des_Go方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EnCodeFile
void CTCCode::EnCodeFile(wchar_t *InFile,wchar_t* key,wchar_t* OutFile)
{
if(InFile&&key&&OutFile)
{
HANDLE infile=::CreateFile(InFile,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(infile!=INVALID_HANDLE_VALUE)
{
HANDLE outfile=::CreateFile(OutFile,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(outfile!=INVALID_HANDLE_VALUE)
{
DES des;
//unicode 转 anscii
int num=::WideCharToMultiByte (CP_ACP,0,key,-1,NULL,0,NULL,NULL);
char* key_l = new char[num];
memset(key_l, 0, num); //初始化动作
WideCharToMultiByte (CP_ACP,0,key, num ,key_l, num ,NULL,NULL);
long lFileLen=::GetFileSize(infile,NULL);
long count=lFileLen/MAXFILESIZE; //整除,知道整个文件的块数
long d=lFileLen%MAXFILESIZE; //取余数
long outLen = 0;
char inbuff[MAXFILESIZE]={0};
char oubuff[MAXFILESIZE]={0};
DWORD ReadFileSize=0;
DWORD DwWitten=0;
for(long i=0;i<count;i++)
{
memset(inbuff,0,sizeof(inbuff));
memset(oubuff,0,sizeof(oubuff));
::ReadFile(infile,inbuff,MAXFILESIZE,&ReadFileSize ,NULL);
des.Des_Go(oubuff, inbuff, sizeof(inbuff), key_l,sizeof(key_l), ENCRYPT1);
::WriteFile(outfile,oubuff,MAXFILESIZE,&DwWitten,NULL);
}
if(d>0)
{
memset(inbuff,0,sizeof(inbuff));
memset(oubuff,0,sizeof(oubuff));
::ReadFile(infile,inbuff,d,&ReadFileSize ,NULL);
des.Des_Go(oubuff, inbuff, MAXFILESIZE, key_l,sizeof(key_l), ENCRYPT1);
::WriteFile(outfile,oubuff,MAXFILESIZE,&DwWitten,NULL);
}
delete [] key_l;
//写入文件长度及结束符
char endmark[2]={0xA3,0xA4};
::WriteFile(outfile,endmark,2,&DwWitten,NULL);
char dsize[2]={0};
itoa(d,dsize,10);
::WriteFile(outfile,dsize,2,&DwWitten,NULL);
}
CloseHandle(outfile);
}
CloseHandle(infile);
}
}
示例2: DeCodeFile
void CTCCode::DeCodeFile(wchar_t *InFile,wchar_t* key,wchar_t* OutFile)
{
if(InFile&&key&&OutFile)
{
HANDLE infile=::CreateFile(InFile,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(infile!=INVALID_HANDLE_VALUE)
{
HANDLE outfile=::CreateFile(OutFile,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(outfile!=INVALID_HANDLE_VALUE)
{
DES des;
//unicode 转 anscii
int num=::WideCharToMultiByte (CP_ACP,0,key,-1,NULL,0,NULL,NULL);
char* key_l = new char[num];
memset(key_l, 0, num); //初始化动作
WideCharToMultiByte (CP_ACP,0,key, num ,key_l, num ,NULL,NULL);
long lFileLen=::GetFileSize(infile,NULL);
char inbuff[MAXFILESIZE]={0};
char oubuff[MAXFILESIZE]={0};
DWORD ReadFileSize=0;
DWORD DwWitten=0;
int writSize = MAXFILESIZE;
////////////////////////读取长度///////////////////////////
lFileLen -= 4;//指定到自己写的结束符位置
SetFilePointer(infile,lFileLen,0,FILE_CURRENT);//设置位置
char inbufftem[4]={0};
char *p=inbufftem;
char endmark[2]={0xA3,0xA4};
::ReadFile(infile,inbufftem,4,&ReadFileSize,NULL);
int dd=0;
if(inbufftem[0]==endmark[0] && inbufftem[1]==endmark[1])
{
p+=2;
dd=atoi(p);
}
SetFilePointer(infile,0,0,FILE_BEGIN);//指针复位
long count=lFileLen/MAXFILESIZE; //整除,知道整个文件的块数
for(long i=0;i<count;i++)
{
memset(inbuff,0,sizeof(inbuff));
memset(oubuff,0,sizeof(oubuff));
::ReadFile(infile,inbuff,MAXFILESIZE,&ReadFileSize ,NULL);
des.Des_Go(oubuff, inbuff, sizeof(inbuff), key_l,sizeof(key_l), DECRYPT);
if(i == count-1)//最后一次进来,处理oubuff值
{
if(dd==0)
dd=MAXFILESIZE;
::WriteFile(outfile,oubuff,dd,&DwWitten,NULL);//最后一次写正确的长度
break;
}
::WriteFile(outfile,oubuff,MAXFILESIZE,&DwWitten,NULL);
}
delete [] key_l;
}
CloseHandle(outfile);
}
CloseHandle(infile);
}
}