All too often I find myself on a Windows system and need to either encode or decode base64. Rather than using an online service, installing a program, or going to a *nix based system, I took to PowerShell. In PowerShell, we can use .NET to accomplish this.
Encoding:
$Text2Encode = ‘PowerShell is Great!’ $Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text2Encode) $EncodedText =[Convert]::ToBase64String($Bytes) $EncodedText
The result is this base64 encoded text:
UABvAHcAZQByAFMAaABlAGwAbAAgAGkAcwAgAEcAcgBlAGEAdAAhAA==
Decoding:
$Data2Decode = “UABvAHcAZQByAFMAaABlAGwAbAAgAGkAcwAgAEcAcgBlAGEAdAAhAA==” $DecodedText = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($Data2Decode)) $DecodedText