From 9a2dfad3de260977138f536b1332404ea1bf5db8 Mon Sep 17 00:00:00 2001 From: Matt Graeber Date: Wed, 16 Dec 2015 10:15:14 -0800 Subject: Fixed mangled decrypted script output Addresses issue #80. This was a tricky fix because the script should ideally handle Unicode and Ascii encoded scripts. I haven't tested scripts with international characters but I would imagine those script would get mangled since the decrypted output is ultimately normalized to ascii. --- ScriptModification/Out-EncryptedScript.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ScriptModification/Out-EncryptedScript.ps1 b/ScriptModification/Out-EncryptedScript.ps1 index 1764d17..eba48f7 100644 --- a/ScriptModification/Out-EncryptedScript.ps1 +++ b/ScriptModification/Out-EncryptedScript.ps1 @@ -90,7 +90,7 @@ This command can be used to encrypt any text-based file/script $AsciiEncoder = New-Object System.Text.ASCIIEncoding $ivBytes = $AsciiEncoder.GetBytes($InitializationVector) # While this can be used to encrypt any file, it's primarily designed to encrypt itself. - [Byte[]] $scriptBytes = [Text.Encoding]::ASCII.GetBytes((Get-Content -Encoding Ascii -Path $ScriptPath)) + [Byte[]] $scriptBytes = Get-Content -Encoding Byte -ReadCount 0 -Path $ScriptPath $DerivedPass = New-Object System.Security.Cryptography.PasswordDeriveBytes($Password, $AsciiEncoder.GetBytes($Salt), "SHA1", 2) $Key = New-Object System.Security.Cryptography.TripleDESCryptoServiceProvider $Key.Mode = [System.Security.Cryptography.CipherMode]::CBC @@ -126,7 +126,8 @@ function de([String] `$b, [String] `$c) `$i.Close(); `$j.Close(); `$f.Clear(); -return `$encoding.GetString(`$h,0,`$h.Length); +if ((`$h.Length -gt 3) -and (`$h[0] -eq 0xEF) -and (`$h[1] -eq 0xBB) -and (`$h[2] -eq 0xBF)) { `$h = `$h[3..(`$h.Length-1)]; } +return `$encoding.GetString(`$h).TrimEnd([Char] 0); } "@ -- cgit v1.2.3