Understanding Base64 Encoding and Decoding Using PowerShell


Whether you're working with APIs, scripting automation, or dealing with file transfers, you’ve probably come across the term Base64. It’s a simple but powerful method used to encode binary data into text – perfect for situations where you need to safely transport or store data that isn’t plain text.
In this post, we’ll break down what Base64 is, why it matters, and how you can easily encode and decode Base64 using PowerShell, without any external tools.
🧠 What is Base64?
Base64 is a binary-to-text encoding scheme. It converts binary data (like images, files, or byte arrays) into ASCII string format by translating it into a radix-64 representation.
✅ Why Use Base64?
Safe to transmit data over text-based systems (like JSON, XML, URLs)
Useful in embedding binary content (like images) directly in text files (e.g., HTML or CSS)
Handy for authentication headers (e.g.,
Basic Auth
in HTTP)
⚡ Encode and Decode Base64 Using PowerShell
No need for any online tool — PowerShell has built-in methods for Base64 encoding and decoding. Here's how to do it right from your terminal or script.
🔒 Encoding a String to Base64
# Input string
$plainText = "Hello World !"
# Convert to bytes
$bytes = [System.Text.Encoding]::UTF8.GetBytes($plainText)
# Encode to Base64
$base64 = [Convert]::ToBase64String($bytes)
# Output
$base64 #SGVsbG8gV29ybGQgIQ==
🔓 Decoding Base64 to Plain Text
# Base64 string
$base64 = "SGVsbG8gV29ybGQgIQ=="
# Convert from Base64 to bytes
$bytes = [Convert]::FromBase64String($base64)
# Convert bytes back to string
$plainText = [System.Text.Encoding]::UTF8.GetString($bytes)
# Output
$plainText #Hello World !
References:
https://stackoverflow.com/questions/15414678/how-to-decode-a-base64-string
Subscribe to my newsletter
Read articles from Mahesh Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
