MFC开发程序,实现加密后删除源文件,解密后删除密文文件

Yuixz 2014-08-19 07:49:54
如题,利用VS2010中MFC开发程序,如何实现以上两个功能。请求帮助!在此谢过
...全文
151 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuyf87 2014-08-28
  • 打赏
  • 举报
回复
利用开源密码库,比如crypto++,选择一种加密算法,比如对称加密算法AES。删除文件调用系统API就可以了。
赵4老师 2014-08-28
  • 打赏
  • 举报
回复
DeleteFile The DeleteFile function deletes an existing file. BOOL DeleteFile( LPCTSTR lpFileName // pointer to name of file to delete ); Parameters lpFileName Pointer to a null-terminated string that specifies the file to be deleted. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks If an application attempts to delete a file that does not exist, the DeleteFile function fails. Windows 95: The DeleteFile function deletes a file even if it is open for normal I/O or as a memory-mapped file. To prevent loss of data, close files before attempting to delete them. Windows NT: The DeleteFile function fails if an application attempts to delete a file that is open for normal I/O or as a memory-mapped file. To close an open file, use the CloseHandle function. Windows CE: If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call GetLastError. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winbase.h. Import Library: Use kernel32.lib. Unicode: Implemented as Unicode and ANSI versions on Windows NT. See Also File I/O Overview, File Functions, CloseHandle, CreateFile
#include <stdio.h>
#include <string.h>
#include <conio.h>
FILE *fi,*fo;
int i;
int main(int argc,char **argv) {
    if (argc<3) {
        printf("Usage:%s src des\n",argv[0]);
        return 1;
    }
    if (0==stricmp(argv[1],argv[2])) {
        printf("Src and des is same!\n");
        return 2;
    }
    fo=fopen(argv[2],"wb");
    if (NULL==fo) {
        printf("Can not create file %s\n",argv[2]);
        return 3;
    }
    fi=fopen(argv[1],"rb");
    if (NULL==fi) {
        fclose(fo);
        printf("Can not find file %s\n",argv[1]);
        return 4;
    }
    i=0;
    fseek(fi,-1L,SEEK_END);
    while (1) {
        fputc(fgetc(fi)^0x5A,fo);
        i++;
        if (i%1000000==0) cprintf("\r%dKB",i/1000);
        if (fseek(fi,-2,SEEK_CUR)) break;
    }
    fclose(fi);
    fclose(fo);
    cprintf("\r%dKB OK.\r\n",i/1000);
    return 0;
}
勤奋的小游侠 2014-08-27
  • 打赏
  • 举报
回复
引用 3 楼 u012620515 的回复:
[quote=引用 2 楼 bubu8633 的回复:] 不过你可以搜索一些给文件加密的实现源代码。
就是找不到相同功能的源码,自己又写不出[/quote] 对加密算法没有要求的话,只需要对数据做简单的循环移位就可以了。 把源文件所有字节循环向左移一位即加密,把密文所有字节向右移一位即为解密
Yuixz 2014-08-27
  • 打赏
  • 举报
回复
引用 2 楼 bubu8633 的回复:
不过你可以搜索一些给文件加密的实现源代码。
就是找不到相同功能的源码,自己又写不出
冷月清晖 2014-08-19
  • 打赏
  • 举报
回复
不过你可以搜索一些给文件加密的实现源代码。
冷月清晖 2014-08-19
  • 打赏
  • 举报
回复
只听说过php等没有编译的脚本语言需要加密。

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧