Windows Command - "certutil -encode/-decode"

This section provides a tutorial example on how to use 'certutil -encode' command on a Windows system to perform Base64 encoding and decoding.

If you are using a Windows system, there is no built-in command to directly perform Base64 encoding and decoding. But you can use the built-in command "certutil -encode/-decode" to indirectly perform Base64 encoding and decoding.

Here is the help information for "certutil":

herong> certutil -encode -?

Usage: 
  CertUtil [Option] -encode InFile Outfile 
  Base64 encode the InFile as an X.509 certificate. 
  
...

Test 1 - Let's encode a short text string of "ABC" from a file, which can be created using the "cat > input.txt" command. We need to press Ctrl-Z and <Enter> to end the input stream from the keyboard.

herong> copy con input.txt
ABC^Z<Enter>

herong> certutil -encode input.txt output.txt

herong> type output.txt 
-----BEGIN CERTIFICATE-----
QUJD
-----END CERTIFICATE-----

Test 2 - Let's decode the encoded string of "QUJD" back.

herong> certutil -decode output.txt decoded.txt

herong> type decoded.txt
ABC

Test 3 - Let's encode the "lazy dog" message:

herong> lazy_dog.txt
The quick brown fox jumps over the lazy dog.

herong> certutil -encode lazy_dog.txt output_2.txt

herong> type output_2.txt
-----BEGIN CERTIFICATE-----
VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZy4=
-----END CERTIFICATE-----

Test 4 - Let's encode a binary file. The output is wrapped into 64-character lines. This form is not the same as 76-character lines used in the MIME (Multipurpose Internet Mail Extensions) specification.

herong> curl http://herongyang.com/_logo.png > icon.png  

herong> certutil -encode icon.png output_3.txt 

herong> type output_3.txt  
-----BEGIN CERTIFICATE-----
VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZy4=

iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAA
AARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEYSURBVEhL7ZbL
DcIwDIYdBGfYADahm1E24QRr9AxLNBvAuUjgJE7ruI5S8RAXPslqaltxfsdSax4I
fJEZPQeMSa2EyLdmTwHCKUhwLmYt1BTIIPIleovkyZUUj8zrrgDzJb0EQovuN64S
bFt7d4/cCLE2bYWFCsxi2e9xutxCwOvormOV3OEMcxJkXLiO55A/vuSIy+MsVrTA
0+5TRfbQ0ErBl9EUIO2hGpxobUUXznzeCO6KCkI0U8DDA5oxuLvcooibjAy2Zq3B
QdEoF8CxsxWtBevdllZ51AJx1KJtGlQtwU4keTiiGmUFGdymU3i5wFTUAuk8BJOM
crpXL/lN/gWKfK6A+A5EpheQYzORr7foB38VHwXgCfzQYOFCEQYGAAAAAElFTkSu
QmCC
-----END CERTIFICATE-----

If you want to get the encoded string into other formats, you need to:

Table of Contents

 About This Book

 Base64 Encoding

Base64 Encoding and Decoding Tools

 Base64.Guru - Base64 Online Tool

Windows Command - "certutil -encode/-decode"

 Linux Command - "base64"

 macOS Command - "base64"

 Java Built-In Implementation of Base64

 Java Built-In Implementation of MIME Base64

 Python Built-In Implementation of Base64

 Python Built-In Implementation of MIME Base64

 PHP Built-In Implementation of Base64

 PHP Built-In Implementation of MIME Base64

 Perl Built-In Implementation of Base64

 Perl Built-In Implementation of MIME Base64

 Base64URL - URL Safe Base64 Encoding

 Base32 Encoding

 URL Encoding, URI Encoding, or Percent Encoding

 UUEncode Encoding

 References

 Full Version in PDF/EPUB