Powershell: Encode and decode Base64 strings

Hi,

short post today. How to en- and decode base64 strings.

Encode a string

[string]$sStringToEncode="My string to encode"
$sEncodedString=[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($sStringToEncode))
write-host "Encoded String:" $sEncodedString

And decoding back

$sDecodedString=[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($sEncodedString))
write-host "Encoded String:" $sDecodedString

Michael

One thought on “Powershell: Encode and decode Base64 strings”

Leave a Reply Cancel reply