By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

obfuscating python

P: 8
My company is looking to launch a program i've written in python commercially , really the main problem we've run into is how to hide an encryption key , is there any way to obfuscate python ?
Jan 10 '07 #1
Share this Question
Share on Google+
6 Replies


bartonc
Expert 5K+
P: 6,596
My company is looking to launch a program i've written in python commercially , really the main problem we've run into is how to hide an encryption key , is there any way to obfuscate python ?
py2exe is discussed here and pyInstaller is discussed here.
Jan 10 '07 #2

dshimer
Expert 100+
P: 136
I'm not totally sure if this applies to what you are asking or doing, but I notice the following which may be of interest.

If I open an exe file created by pyInstaller single file method (which I prefer), in a text editor, the complete text of the original script is still recognizable. My intent isn't to hide the source script, so I haven't researched to see if it is possible to do so, but if that was a goal I would want to be aware of it.

I don't notice the same thing in files created by py2exe but have done very little digging and would be curious if it would really be that hard to "decompile" an exe created that way as well. Though this certainly wouldn't be as big a concern as the plain text I seen in the first example.
Jan 10 '07 #3

P: 8
i've tried using py_compile , it converts most of the file to byte code but it still leaves the strings that i need unreadable readable.

thanks for the suggestion about py2exe , that will save me some time down the road
Jan 10 '07 #4

bartonc
Expert 5K+
P: 6,596
i've tried using py_compile , it converts most of the file to byte code but it still leaves the strings that i need unreadable readable.

thanks for the suggestion about py2exe , that will save me some time down the road
One thing that isn't too hard is to put critical sections of your program in a C module (dll) and import that.
Jan 10 '07 #5

P: 36
Check in the archives of comp.lang.python... this topic has come up several times in the past.

The main problem is that your code is always available, at least in byte-code format. As you noted, strings are always stored literally.

You can obfuscate your key trivially by using something like:

#instead of:
key="1234567890"

#use:
key="".join([chr(ch) for ch in [0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x30])

or whatever more complex scheme you can dream up, but you need to remember that however you do it, someone could always decode it by de-compiling the bytecode and running it through the python debugger.

Your best bet is to write a C module that stores and does the key handling, and implement your obfuscation in there.

Note that there is *no* way to make it *impossible* for someone to reverse-engineer the key... but you can raise the bar. It depends on how desirable pirated copies of your software are. Just look at how quickly Blu-Ray encryption got compromised.

The cheapest and most secure way would probably be to use a USB dongle.

hth,
-cybervegan
Jan 11 '07 #6

bartonc
Expert 5K+
P: 6,596
Check in the archives of comp.lang.python... this topic has come up several times in the past.

The main problem is that your code is always available, at least in byte-code format. As you noted, strings are always stored literally.

You can obfuscate your key trivially by using something like:

#instead of:
key="1234567890"

#use:
key="".join([chr(ch) for ch in [0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x30])

or whatever more complex scheme you can dream up, but you need to remember that however you do it, someone could always decode it by de-compiling the bytecode and running it through the python debugger.

Your best bet is to write a C module that stores and does the key handling, and implement your obfuscation in there.

Note that there is *no* way to make it *impossible* for someone to reverse-engineer the key... but you can raise the bar. It depends on how desirable pirated copies of your software are. Just look at how quickly Blu-Ray encryption got compromised.

The cheapest and most secure way would probably be to use a USB dongle.

hth,
-cybervegan
Great post, cybervegan! Welcome to the python forum on TSDN. I hope that you stick around,
Barton
Jan 11 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.