经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » MS DOS命令 » 查看文章
cmd实现文件的base64加密并双击加密文件后正常运行
来源:cnblogs  作者:feiquan  时间:2018/12/28 9:42:48  对本文有异议

  之前,一个朋友让我用cmd做个简单的文档加密(base64),对于不太懂电脑的人来说看不懂就行。但是当那个人点击加密后的文件可以正常运行,问咋写?

  其实,像这种要求不高的加密来说,随便下载个加密软件就好。但是对加密后的文件直接双击就可以和源文件那样直接运行就很少了。

  这里我们用到的是windows自带的certutil命令,有关其命令的详解,大家直接执行certutil /? 就可以查看。

以下是我写的bat文件:

其中:

1.readme.txt  说明文档

  1. 使用说明:
  2.   1.将你要加密的文件复制到Material文件夹下,如果没有Material可以自己新建
  3.   2.双击ClickToEncodeFiles.bat文件,加密Material文件夹下的文件
  4.   3.打开encodeFiles文件夹,其中就是加密后的文件
  5. 注意:
  6.   1.加密的文件名不能有空格
  7.   2.每次会输出加密的结果注意查看。

 

2.ClickToEncodeFiles.bat 运行文档

  1. @echo off
  2. chcp 936
  3. if not "%OS%"=="Windows_NT" exit
  4. title EncodeFiles
  5. color 0a
  6. more readme.txt
  7. pause
  8. chcp 65001>nul
  9. setlocal EnableDelayedExpansion
  10. rem 创建需要的文件夹
  11. REM if not exist decodeFiles mkdir decodeFiles
  12. if not exist encodeFiles mkdir encodeFiles
  13. if not exist Material (
  14. mkdir Material
  15. echo Please put the files which you want to encrypt in the "Material" folder of the current directory.
  16. pause
  17. exit
  18. )
  19. REM Encrypt Files in the "Material" folder of the current directory
  20. echo Please ensure your encrypt files in Material folder .
  21. echo=
  22. set finallyPath=-1
  23. for /F "tokens=1 delims=/" %%i in ('dir /b /on Material') do (
  24. echo Start encode %%i
  25. set finallyPath=".\encodeFiles\%%i.bat"
  26. REM echo !finallyPath!
  27. rem decode code
  28. echo @echo off > !finallyPath!
  29. echo certutil -f -decode "%%0" %%temp%%\%%i ^>nul >>!finallyPath!
  30. echo start %%temp%%\%%i>>!finallyPath!
  31. REM echo pause >>!finallyPath!
  32. echo exit >>!finallyPath!
  33. echo= >>!finallyPath!
  34. certutil -F -encode ".\Material\%%i" "%temp%\%%i.txt" | find "FAILED" >nul && ( echo %%i encode defeated ^!^!^!^! & echo= )|| ( echo %%i encode passed & echo= )
  35. more "%temp%\%%i.txt" >>!finallyPath!
  36. if exist "%temp%\%%i.txt" del "%temp%\%%i.txt"
  37. )
  38. start .\encodeFiles\
  39. pause
  40. exit

3.Material 中是要加密的文件

4.encodeFiles 是加密完成后的文件,双击可运行

 

下载地址:

  https://github.com/feiquan123/encodeFiles/

 

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号