之前,一個朋友讓我用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/