mfc如何将文本数据加密

847
2021/2/9 15:41:47
栏目: 网络安全
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

mfc如何将文本数据加密

使用mfc对文本数据进行加密的方法

mfc代码如下:

#include "stdafx.h"

#include "EncodeAndDecode.h"

#include "afxdialogex.h"

EncodeAndDecode::EncodeAndDecode()

{

}

EncodeAndDecode::~EncodeAndDecode()

{

}

void EncodeAndDecode::EncodeFile()

{

//读取配置文件

CString fPath("./data.txt");

CFile openFile;

bool bFile = openFile.Open(fPath, CFile::modeRead);

//同根目录下判断是否打开

if (!bFile)

{

MessageBox(NULL,_T("系统文件丢失请联系管理员"), _T("错误") ,MB_ICONINFORMATION);

exit(0);

}

DWORD openSize = (DWORD)openFile.GetLength();

char* buf = new char[openSize + 1];

memset(buf, 0, sizeof(char) * (openSize + 1));

openFile.Read(buf, openSize);

openFile.Close();

//加密算法

for (unsigned int i = 0; i < openSize; i++)

{

buf[i] = 255 - buf[i];

}

//写入加密文件

CString wPath("./moon.xie");

CFile writeFile;

writeFile.Open(wPath, CFile::modeWrite | CFile::modeCreate);

writeFile.Write(buf, openSize);

writeFile.Close();

//MessageBox(NULL, _T("已加密"), _T("成功"), MB_ICONINFORMATION);

}

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: mfc控件工具栏如何打开