Encode / Decode .EXE into Base64

The problem was caused by:

  1. Get-Content without -raw splits the file into an array of lines thus destroying the code
  2. Text.Encoding interprets the binary code as text thus destroying the code
  3. Out-File is for text data, not binary code

The correct approach is to use IO.File ReadAllBytes:

$base64string = [Convert]::ToBase64String([IO.File]::ReadAllBytes($FileName))

and WriteAllBytes to decode:

[IO.File]::WriteAllBytes($FileName, [Convert]::FromBase64String($base64string))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)