Base64 decoding in batch mode

I am trying to make an installer using a package. Of course, the installer should consist of files that will be installed, so I'm thinking of encoding the files in base64 and just decode them and write them to the destination.

Of course, my work will be very simple if on Windows there is something like a base64 tool that contains Linux boxes. However, since it simply does not exist, is there a way to completely decode the contents of base64 using batch files? And how would I do that?

Any help is appreciated.

(This is just an experiment, so I'm not worried about inefficiency, etc.)

+73
windows base64 batch-file
Jun 05 '13 at 17:02
source share
2 answers

In fact, Windows has a utility that encodes and decodes base64 - CERTUTIL

I'm not sure which version of Windows introduced this command.

To encode a file:

 certutil -encode inputFileName encodedOutputFileName 

To decode a file:

 certutil -decode encodedInputFileName decodedOutputFileName 

There are a number of verbs available and options available for certutil.

To get a list of almost all available verbs:

 certutil -? 

To get help with a specific verb (e.g. -encode):

 certutil -encode -? 

To get full help for almost all verbs:

 certutil -v -? 

Mysteriously, the -encodehex verb -encodehex not listed in certutil -? or certutil -v -? But this is described using certutil -encodehex -? , This is another convenient feature :-)

Refresh

Regarding David Morales's comment, the -encodehex verb -encodehex has a poorly documented type option that allows you to create base64 lines without header or footer lines.

 certutil [Options] -encodehex inFile outFile [type] 

Type 1 will give base64 without header or footer lines.

See https://www.dostips.com/forum/viewtopic.php?f=3&t=8521#p56536 for a short list of available type formats. And for a more detailed look at the available formats, see https://www.dostips.com/forum/viewtopic.php?f=3&t=8521#p57918 .

Not explored, but the -decodehex verb also has an optional type -decodehex argument.

+147
Jun 05 '13 at 17:55
source share

Here is a batch file called base64encode.bat that encodes 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% 
+5
Jan 30 '17 at 19:55
source share



All Articles