Is it possible to encrypt a "modul"?

May 2, 2013 at 1:06 PM
Hello,

I want crypt a PowerShell script that included some functions which I would like to protect. Is it possible to encrypt the script and then load this functions from a other .ps1 to use this functions?

Like:
Import-Module "$currentPath\Initialize.exe"

Thanks
Coordinator
May 2, 2013 at 1:56 PM
Hi!

This is not possible, because PS2EXE uses an own PowerShell environment that only exist while running the generated EXE file.

To achieve your goal you could "encrypt" you initialization script with several methods like Base64. But this is no real encryption! A power user would be able to "decrypt" it. PowerShell is not a good choice if you need to secure or protect your scripts / functions.

Hope this helps
Ingo
May 2, 2013 at 2:48 PM
Edited May 2, 2013 at 2:49 PM
Hi Ingo,

Thanks for answer.
I've now a workaround, that works for me :-)

Sample:
I create a Test1.ps1 with my function and a Test2.ps2 where i can call the functions:

Test1.ps1
Function TestFunction {
write-host "Very cool"
}

. "C:\Temp\PS2EXE-v0.4.0.0\Test2.ps1"


Test2.ps1
TestFunction

Now i can encrypt the Test1.ps1 und run the EXE.
Functions are loaded and then run the Test2.ps1 where i can call my function :-)