Convert From Base64 With Powershell Script
Oct 16, 2020
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.