Often I have requirements to change a password somewhere using a Powershell script and am required to enter it at run time. At this point, one has an option: include the password in a log file or not. I figured it would be good to have it in the log file (the script is run on a trusted box), but plain text isn’t best. How to do this?
That’s when I thought of base64.
Here’s Powershell code to perform these actions:
## Display & Log Base64 Encoded password
$Encoded = [System.Text.Encoding]::UTF8.GetBytes($Password)
$EncodedPassword = [System.Convert]::ToBase64String($Encoded)
## Display & Log Base64 Decoded password
$Decoded = [System.Convert]::FromBase64String($Password);
$DecodedPassword = [System.Text.Encoding]::UTF8.GetString($Decoded );
Write-Output "Password ($Password) Base64 decoded is $DecodedPassword "