批量解码base64

use*_*000 77 windows base64 batch-file

我正在尝试使用批处理来制作安装程序.当然,安装程序需要包含将要安装的文件,因此我正在考虑在base64中对文件进行编码,并简单地对它们进行解码并将它们写入目标.

当然,如果Windows有类似base64Linux机箱所包含的工具,我的工作将非常容易.但是,由于它根本就不存在,有没有办法使用批处理文件完全解码base64内容?我怎么做到这一点?

任何帮助表示赞赏.

(这只是一个实验,所以我并不担心效率低下等.)

dbe*_*ham 153

实际上,Windows确实有一个实用程序可以对base64 - CERTUTIL进行编码和解码

我不确定哪个版本的Windows引入了这个命令.

要编码文件:

certutil -encode inputFileName encodedOutputFileName
Run Code Online (Sandbox Code Playgroud)

解码文件:

certutil -decode encodedInputFileName decodedOutputFileName
Run Code Online (Sandbox Code Playgroud)

CERTUTIL提供了许多可用的动词和选项.

要获得几乎所有可用动词的列表:

certutil -?
Run Code Online (Sandbox Code Playgroud)

要获得特定动词的帮助(例如-encode):

certutil -encode -?
Run Code Online (Sandbox Code Playgroud)

要获得几乎所有动词的完整帮助:

certutil -v -?
Run Code Online (Sandbox Code Playgroud)

神秘的-encodehex是,动词未列出certutil -?certutil -v -?.但它是用来描述的certutil -encodehex -?.这是另一个方便的功能:-)

  • 我会给出一些很好的机会,"批量生成的base64"是我在搜索引擎中输入的最绝望的东西 (33认同)
  • [Certutil](http://technet.microsoft.com/library/cc732443.aspx)至少已经存在[Windows Server 2003](http://msdn.microsoft.com/en-us/subscriptions/cc773087. ASPX). (8认同)
  • 运行`certutil -encode inputFileName encodedOutputFileName`生成一个由"----- BEGIN CERTIFICATE -----"和"----- END CERTIFICATE -----"包围的base64字符串,这样就无法直接解码生成后的文件. (4认同)
  • @AndrzejMartyna - 它不是坏了,但最大输入文件大小为74472684字节. (4认同)
  • @DavidMorales - 不是这样!你试过吗?-DECODE命令适用于页眉和页脚.我不确定具体规则,但CERTUTIL -DECODE对编码源的格式非常宽容. (2认同)

BSa*_*ita 5

这是一个名为base64encode.bat的批处理文件,它对base64进行编码。

@echo off
if not "%1" == "" goto :arg1exists
echo usage: base64encode input-file [output-file]
goto :eof
:arg1exists
set base64out=%2
if "%base64out%" == "" set base64out=con 
(
  set base64tmp=base64.tmp
  certutil -encode "%1" %base64tmp% > nul
  findstr /v /c:- %base64tmp%
  erase %base64tmp%
) > %base64out%
Run Code Online (Sandbox Code Playgroud)

  • 如果添加`setlocal enabledelayedexpansion`并在((...)`内使用`base64tmp!`,此脚本将更好地工作。否则,该值是在读入(...)序列时确定的,而不是在执行该序列时确定的。 (2认同)
  • 一个更简单的解决方案,无需处理标头:/sf/answers/4228297881/ (2认同)