如何保护 Python 代码不被用户阅读? [英] How do I protect Python code from being read by users?

查看:95
本文介绍了如何保护 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?

推荐答案

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天全站免登陆