如何保护Python代码? [英] How do I protect Python code?

查看:146
本文介绍了如何保护Python代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Python开发一款软件,该软件将分发给我的雇主的客户.我的雇主想通过限时许可文件来限制软件的使用.

I am developing a piece of software in Python that will be distributed to my employer's customers. My employer wants to limit the usage of the software with a time restricted license file.

如果我们分发.py文件或什至.pyc文件,将很容易(反编译和)删除检查许可证文件的代码.

If we distribute the .py files or even .pyc files it will be easy to (decompile and) remove the code that checks the license file.

另一方面是,我的雇主不希望我们的客户阅读该代码,因为担心该代码可能被盗或至少是新颖的主意".

Another aspect is that my employer does not want the code to be read by our customers, fearing that the code may be stolen or at least the "novel ideas".

是否有解决此问题的好方法?最好使用现成的解决方案.

Is there a good way to handle this problem? Preferably with an off-the-shelf solution.

该软件将在Linux系统上运行(因此,我认为py2exe不会成功).

The software will run on Linux systems (so I don't think py2exe will do the trick).

推荐答案

Python是一种字节码编译的解释语言,很难锁定.即使您使用 py2exe 之类的exe打包程序,可执行文件的布局也是众所周知的,并且Python字节码众所周知.

Python, being a byte-code-compiled interpreted language, is very difficult to lock down. Even if you use a exe-packager like py2exe, the layout of the executable is well-known, and the Python byte-codes are well understood.

通常,在这种情况下,您必须进行权衡.保护代码真的有多重要?那里是否有真正的秘密(例如,对银行转账进行对称加密的密钥),或者您只是偏执?选择一种语言,使您能够最快地开发出最好的产品,并要对自己的新颖思想的价值抱有现实的态度.

Usually in cases like this, you have to make a tradeoff. How important is it really to protect the code? Are there real secrets in there (such as a key for symmetric encryption of bank transfers), or are you just being paranoid? Choose the language that lets you develop the best product quickest, and be realistic about how valuable your novel ideas are.

如果您确定确实需要安全地执行许可证检查,请将其编写为一个小的C扩展名,以使许可证检查代码可以特别困难(但并非不可能!)来进行反向工程,并节省大量工作量Python中的代码.

If you decide you really need to enforce the license check securely, write it as a small C extension so that the license check code can be extra-hard (but not impossible!) to reverse engineer, and leave the bulk of your code in Python.

这篇关于如何保护Python代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆