之前,一个朋友让我用cmd做个简单的文档加密(base64),对于不太懂电脑的人来说看不懂就行。但是当那个人点击加密后的文件可以正常运行,问咋写?
其实,像这种要求不高的加密来说,随便下载个加密软件就好。但是对加密后的文件直接双击就可以和源文件那样直接运行就很少了。
这里我们用到的是windows自带的certutil命令,有关其命令的详解,大家直接执行certutil /? 就可以查看。
以下是我写的bat文件:

其中:
1.readme.txt 说明文档
- 使用说明:
- 1.将你要加密的文件复制到Material文件夹下,如果没有Material可以自己新建
- 2.双击ClickToEncodeFiles.bat文件,加密Material文件夹下的文件
- 3.打开encodeFiles文件夹,其中就是加密后的文件
- 注意:
- 1.加密的文件名不能有空格
- 2.每次会输出加密的结果注意查看。
2.ClickToEncodeFiles.bat 运行文档
- @echo off
- chcp 936
- if not "%OS%"=="Windows_NT" exit
- title EncodeFiles
- color 0a
- more readme.txt
- pause
- chcp 65001>nul
- setlocal EnableDelayedExpansion
- rem 创建需要的文件夹
- REM if not exist decodeFiles mkdir decodeFiles
- if not exist encodeFiles mkdir encodeFiles
- if not exist Material (
- mkdir Material
- echo Please put the files which you want to encrypt in the "Material" folder of the current directory.
- pause
- exit
- )
- REM Encrypt Files in the "Material" folder of the current directory
- echo Please ensure your encrypt files in Material folder .
- echo=
- set finallyPath=-1
- for /F "tokens=1 delims=/" %%i in ('dir /b /on Material') do (
- echo Start encode %%i
- set finallyPath=".\encodeFiles\%%i.bat"
- REM echo !finallyPath!
- rem decode code
- echo @echo off > !finallyPath!
- echo certutil -f -decode "%%0" %%temp%%\%%i ^>nul >>!finallyPath!
- echo start %%temp%%\%%i>>!finallyPath!
- REM echo pause >>!finallyPath!
- echo exit >>!finallyPath!
- echo= >>!finallyPath!
- certutil -F -encode ".\Material\%%i" "%temp%\%%i.txt" | find "FAILED" >nul && ( echo %%i encode defeated ^!^!^!^! & echo= )|| ( echo %%i encode passed & echo= )
- more "%temp%\%%i.txt" >>!finallyPath!
- if exist "%temp%\%%i.txt" del "%temp%\%%i.txt"
- )
- start .\encodeFiles\
- pause
- exit
3.Material 中是要加密的文件
4.encodeFiles 是加密完成后的文件,双击可运行
下载地址:
https://github.com/feiquan123/encodeFiles/