pythonpyinstallerexereverse-engineeringnuitka

How to convert python to exe without strings saved in the exe file?


I want to convert my python project to an Exe file using Nuitka/Pyinstaller, but unfortunately, all of the strings I wrote in the python file, can be found easily inside of the Exe file just by opening the Exe file with notepad.

How can I convert my project to Exe and fully hide the strings and passwords saved inside the py file?


Solution

  • As the comments have mentioned if you want the user to know something only when you want to tell them, not by inspecting the binary, you should try to obfuscate it.

    One way of achieving it is, as also suggested in the comments, by encryption. You can convert your .json file to a string and then encrypt it with a given password, which the binary will be aware of, of course.

    You can also, which is probably more simple, just encode the string, for example in base 64 and then when calling it you would decode it back again. A small example is as follows:

    import base64
    s = "your json file as string here".encode("utf-8")
    encoded = base64.b64encode(s)
    

    And now each you want to use the string you decode it with:

    decoded = base64.b64decode(encoded)
    

    And it shouldn't be available to the end user by inspecting the binary.

    Although this is theory doesn't actually prevent an expert user from figuring out what's really written in there, even with encryption, if you hold the encrypted content and the key, then its just a matter of putting the pieces together.