igreenius
Posts: 11
Joined: Wed Aug 19, 2015 7:26 am

Encrypt Python Code

Mon Sep 14, 2015 4:37 am

I am running a script which is accessing sites and providing account credentials. Is there a way to encrypt my python code to hide the login credentials?

Any approach will be highly appreciated. TIA

beta-tester
Posts: 1377
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Encrypt Python Code

Mon Sep 14, 2015 2:50 pm

encryption of entire python script code (*.py), is as long as i know, not possible.
even if you have your python code available as compiled only (*.pyc), you are able to see the strings and names inside very easily.

you never should put plain credential information in your source code...
if you you have to put credential information to your source code, you should put them very good encoded there and decode them at runtime ans hold them in plain format for as short time as possible in ram...

but even then it is possible to analyse your python script code (*.py) to reconstruct the way how to decode.
from a compiled python files (*.pyc) it is a bit more difficult do reconstruct, but for pro's it is still no big problem.
(or observe the memory to see the plain information somewhen in the memory dump)
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Encrypt Python Code

Mon Sep 14, 2015 6:35 pm

The best way is to encrypt the login, keep that as a string and then hash the password the user enters and if it is the same, the password matches, but the real password can never be deciphered.
There are 10 types of people: those who understand binary and those who don't.

igreenius
Posts: 11
Joined: Wed Aug 19, 2015 7:26 am

Re: Encrypt Python Code

Tue Sep 15, 2015 9:44 am

Thanks guys!
I think the pyc format is enough for this one but I'll try other advanced methods like you guys said when things got 'serious'. : )

beta-tester
Posts: 1377
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Encrypt Python Code

Tue Sep 15, 2015 2:05 pm

igreenius wrote:Thanks guys!
I think the pyc format is enough for this one but I'll try other advanced methods like you guys said when things got 'serious'. : )
as i saied.... if you open a pyc file in a hex viewer or text editor, you may see strings, variable-, class-names in plain text.
i highly recommend you to put only encrypt strings that contains credential informations to your code and decode them at runtime.
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

Return to “Beginners”