py-gen-mur
python 机器码/用户码/注册码 生成器
python generate [m]achine_code [u]ser_code [r]egister_code
运行环境
使用场景说明
使用场景详见 测试用例 。
场景步骤一(管理员本地,可选)
因代码开源,不建议使用 mur.crypt.Crypt() 默认类。
建议使用此工具时,自定义指定 mur.crypt.Crypt() 构造函数的 key 和 iv 。
本代码中提供了 mur.crypt.gen_des_key() 和 mur.crypt.gen_des_iv() 的方法,但是生成后必须找地方另外存储这两个值,否则之前使用其生成的注册码无法再解密。
from mur.crypt import *
my_des_key = gen_des_key()
my_des_iv = gen_des_key()
my_crypt = Crypt(
key = my_des_iv,
iv = my_des_iv
)
场景步骤二(用户本地)
- 用户运行【生成机器码】的程序
- 生成放有【加密机器码】的文件
- 把【加密机器码】的文件提供给管理员
from mur.user import *
u_machine_code = gen_machine_code(my_crypt)
实际使用时可复制
gen_register_code.py到需要发布的程序,由用户执行生成【机器码】
场景步骤三(管理员本地)
- 管理员解密用户提供的【加密机器码】文件
- 同时为用户设置授权天数,生成【用户码】文件
- 结合两者生成【注册码】文件
- 把【用户码】文件和【注册码】文件提供给用户
from mur.admin import *
a_machine_code = read_machine_code()
days = input('请输入授权天数:') # 0 表示永久
a_user_code = gen_user_code(days, my_crypt)
a_register_code = gen_register_code(
a_machine_code, a_user_code, my_crypt
)
实际使用时可在本仓库中执行
python gen_register_code.py为用户生成【用户码】和【注册码】
场景步骤四(用户本地)
- 用户运行应用主程序
- 主程序读取【用户码】文件(或让用户输入用户码)
- 主程序在用户本地重新生成【机器码】
- 主程序利用【用户码】和【机器码】生成【注册码】
- 主程序比对【生成的注册码】和【管理员提供的注册码】内容是否一致
- 若一致,且授权未过期,程序运行;否则,程序终止
from mur.user import *
u_user_code = read_user_code()
rst = verify_authorization(u_user_code, my_crypt)
if rst == True :
app.run()
else :
exit(1)
使用注意
凡是使用了此工具的程序,在发布该程序时,建议不要直接用 Pyinstaller 打包成 *.pyc,然后供用户使用,否则很容易被反编译破解。
建议先对源码做加密处理,再提供给用户使用。有两个方法,任选一个即可:
Cython 编译为动态链接
- 先使用
Cython生成*.py的动态连接*.pyd文件 - 再使用
Pyinstaller打包,才供用户使用。
可参考文档《Cython + Pyinstaller 防止反编译打包》
Pyinstaller 加密
- 先用 pip 命令安装
tinyaes和pycrypto(需要提前安装 Microsoft Visual Studio 和设置环境变量 CL) - 使用
Pyinstaller打包时增加--key ${password}(此时编译的中间文件为*.pyc.encrypted)。
可参考文档:
- 《Pyinstaller 打包的 exe 之一键反编译 py 脚本与防反编译》
- 《谈谈 Pyinstaller 的编译和反编译,如何保护你的代码》
- 《Microsoft Windows Python-3.6 PyCrypto installation error》
赞助途径
| 支付宝 | 微信 |
|---|---|
版权声明
- Site: http://exp-blog.com
- Mail: 289065406@qq.com
Metadata
Release files for py-gen-mur 1.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| py-gen-mur-1.1.5.tar.gz | 14.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_gen_mur-1.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.1 kB
Release files / py-gen-mur-1.1.5.tar.gz
| Download URL | py-gen-mur-1.1.5.tar.gz |
|---|---|
| Size | 14.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d76573d6bcffad145190636b299be37fb5fbc12f662475ef55f3a4826702655
|
|
BLAKE2b-256 checksum How to use checksums |
58d892657dd550c54a551fc224819096f891c428c776c97a97816b28b8bf6ec4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Release files / py_gen_mur-1.1.5-py3-none-any.whl
| Download URL | py_gen_mur-1.1.5-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4cdd1befa13d11ba48a8b0592a5b7d1276b39bfd6422dfc4fd6b178f5860f2fe
|
|
BLAKE2b-256 checksum How to use checksums |
eeff66252e5a5e1bbdaf32cdcdb8fb94d93f8e6f8438d1c534e222b255bae786
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|