Convert From Base64 With Powershell Script

1. steps

  • capture the encoded string in fiddler
  • pass that into the command decode-base64 -data <$string>
  • get the result as encoded `json`
  • this is what echo $string | jq '.' is doing in bash

2. demo

  • decoding aGVsbG8gd29ybGQ= into hello world

3. script

function decode-base64 {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$data
)
begin {
$intro = @"
_____
/ _T_ \ presents..
/ / E \ \ ..BASE64 STRING DECODER
\ \_I_/ / ....just pass the string with the cmdlet / function call
\__N__/ ....results in clipboard & file
"@
Write-Host $intro -ForegroundColor cyan
$outputFile = "$env:USERPROFILE\documents\decoded.json"
}
process {
$convertedData = [Convert]::FromBase64String($data)
$stringData = [System.Text.Encoding]::UTF8.GetString($convertedData)
}

end {
Write-Host "~~~~~~~~~~~~~~~~~~~~~~~~~~~" -ForegroundColor cyan
Write-Host "decoded string:" -ForegroundColor cyan
Write-Host "~~~~~~~~~~~~~~~~~~~~~~~~~~~" -ForegroundColor cyan
Write-Host $stringData
Write-Host "~~~~~~~~~~~~~~~~~~~~~~~~~~~" -ForegroundColor cyan
Write-Host "copied to clipboard & to $outputFile"
Write-Host "~~~~~~~~~~~~~~~~~~~~~~~~~~~" -ForegroundColor cyan
$stringData | Out-File $outputFile -Force
$stringData | clip
Pause
ii $outputFile
}
}

Originally published at http://pavol.kutaj.com on October 18, 2020.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store