I have a .NET exe file that I would like to encode into a Base-64 string, and then at a later point decode a .exe file from a Base64 string using Powershell.
That I still create the .exe file , however, this file is not recognized for windows as an application that can run, and is always different from the file, m, which go into the script encoding.
I think I can use the wrong encoding here, but I'm not sure.
Encode script:
Function Get-FileName($initialDirectory) { [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog $OpenFileDialog.initialDirectory = $initialDirectory $OpenFileDialog.filter = "All files (*.*)| *.*" $OpenFileDialog.ShowDialog() | Out-Null $FileName = $OpenFileDialog.filename $FileName }
Decoding script:
$Data = get-content $FileName $Bytes = [System.Text.Encoding]::UTF8.GetBytes($Data) $EncodedData = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($Bytes)) $EncodedData | Out-File ( $FileName )
source share