资源简介
主体部分vc6.0编写,界面用了vc2003。很值得学习和借鉴
代码片段和文件信息
#include “stdafx.h“
#include “Rijndael.h“
#include “.\AESEncryption.h“
CAESEncryption::CAESEncryption(void)
{
memset(KeyData 0 16);
memcpy(KeyData“1234567890123456“ 16);
/* 调试
char In[32];
char Out[32];
memcpy(In“a\0aaaaaaaaaaaaaba\0aaaaaaaaaaaaab“32);
DWORD nSize = 32;
Encryption(In32Out&nSize);
memset(In 0 32);
Decryption(Out 32 In);
*/
}
CAESEncryption::~CAESEncryption(void)
{
}
//加密函数
bool CAESEncryption::Encryption(IN LPVOID lpData IN DWORD nByte OUT LPVOID lpOutData IN OUT DWORD* nSize)
{
CRijndael aes;
char* lpInData = NULL;
char lpInBlock[16] = {0};
char lpOutBlock[16] = {0};
DWORD nInBufferSize = nByte % 16;
DWORD nBlockCount = 0;
char* lpOutPointer = NULL;
//计算大小,开辟16的倍数的内存
if (nInBufferSize != 0) {
nInBufferSize = ((nByte / 16) + 1) * 16;
} else {
nInBufferSize = nByte;
}
nBlockCount = nInBufferSize / 16;
//计算输出缓冲区是否够大
if (*nSize < nInBufferSize) {
*nSize = nInBufferSize;
return false;
}
*nSize = nInBufferSize;
//拷贝需要加密的数据
lpInData = new char[nInBufferSize];
memset(lpInData 0 nInBufferSize);
memcpy(lpInData lpData nByte);
memset(lpOutData 0 *nSize);
lpOutPointer = (char*)lpOutData;
//设置加密密钥
aes.MakeKey(KeyData CRijndael::sm_chain0);
//分块加密
for (DWORD i = 0; i < nBlockCount; i++)
{
memset(lpInBlock 0 16);
memset(lpOutBlock 0 16);
memcpy(lpInBlock lpInData + i * 16 16);
aes.EncryptBlock(lpInBlock lpOutBlock);
//拷贝到输出缓冲区
memcpy(lpOutPointer lpOutBlock 16);
//移动指针
lpOutPointer += 16;
}
return true;
}
//解密函数
bool CAESEncryption::Decryption(IN LPVOID lpData IN DWORD nByte OUT LPVOID lpOutData)
{
CRijndael aes;
DWORD n = nByte % 16;
char cInBlock[16];
char cOutBlock[16];
char* lpOutPointer = NULL;
//判断缓冲区长度是否符合 16 的倍数
if (n != 0) {
return false;
}
//计算块的数量
DWORD nBlockCount = nByte / 16;
//输出指针
lpOutPointer = (char*)lpOutData;
//设置加密密钥
aes.MakeKey(KeyData CRijndael::sm_chain0);
//分块解密
for (DWORD i = 0; i < nBlockCount ; i++)
{
memset(cInBlock 0 16);
memset(cOutBlock 0 16);
memcpy(cInBlock (LPBYTE)lpData + i * 16 16);
aes.DecryptBlock(cInBlock cOutBlock);
memcpy(lpOutPointer cOutBlock 16);
lpOutPointer += 16;
}
return true;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2446 2008-06-18 18:01 捆绑机\捆绑机\Binder\AESEncryption.cpp
文件 383 2008-06-18 17:42 捆绑机\捆绑机\Binder\AESEncryption.h
文件 1452 2008-06-09 13:03 捆绑机\捆绑机\Binder\Binder.cpp
文件 437 2008-06-09 13:03 捆绑机\捆绑机\Binder\Binder.h
文件 8031 2008-06-18 18:49 捆绑机\捆绑机\Binder\Binder.rc
文件 5276 2008-06-18 16:25 捆绑机\捆绑机\Binder\Binder.vcproj
文件 16930 2008-06-18 18:50 捆绑机\捆绑机\Binder\BinderDlg.cpp
文件 2102 2008-06-18 18:27 捆绑机\捆绑机\Binder\BinderDlg.h
文件 14814 2008-06-16 18:17 捆绑机\捆绑机\Binder\Hyperli
文件 3711 2008-02-01 10:55 捆绑机\捆绑机\Binder\Hyperli
文件 4635 2008-06-18 18:07 捆绑机\捆绑机\Binder\IconDlg.cpp
文件 854 2008-06-18 15:34 捆绑机\捆绑机\Binder\IconDlg.h
文件 2800 2008-06-09 13:03 捆绑机\捆绑机\Binder\ReadMe.txt
文件 404 2008-06-09 16:02 捆绑机\捆绑机\Binder\removejunk.bat
文件 596 2008-06-09 13:07 捆绑机\捆绑机\Binder\res\1.xm
文件 19942 2007-05-01 13:34 捆绑机\捆绑机\Binder\res\Binder.ico
文件 21630 2003-04-01 19:36 捆绑机\捆绑机\Binder\res\Binder.ico.bak
文件 362 2008-06-09 13:03 捆绑机\捆绑机\Binder\res\Binder.rc2
文件 1078 2006-10-05 10:25 捆绑机\捆绑机\Binder\res\main.ico
文件 1916 2008-06-16 20:17 捆绑机\捆绑机\Binder\resource.h
文件 58904 2008-06-18 16:34 捆绑机\捆绑机\Binder\Rijndael.cpp
文件 6150 2008-06-18 16:34 捆绑机\捆绑机\Binder\Rijndael.h
文件 133 2008-06-09 15:41 捆绑机\捆绑机\Binder\stdafx.cpp
文件 1651 2008-06-17 19:22 捆绑机\捆绑机\Binder\stdafx.h
文件 115718 2008-06-16 18:16 捆绑机\捆绑机\Binder\zip\zip.cpp
文件 10044 2005-07-28 01:09 捆绑机\捆绑机\Binder\zip\zip.h
文件 376832 2010-04-23 23:24 捆绑机\捆绑机\Binder.exe
文件 2 2008-06-16 17:37 捆绑机\捆绑机\VC6\Studio\1.txt
文件 2898 2010-04-23 23:15 捆绑机\捆绑机\VC6\Studio\AESEncryption.cpp
文件 383 2008-06-18 17:42 捆绑机\捆绑机\VC6\Studio\AESEncryption.h
............此处省略46个文件信息
- 上一篇:电力行业规约645通信的VC++实现源码
- 下一篇:多边形合并c# c++
评论
共有 条评论