python generate machine_code, user_code, register_code
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py-gen-mur-1.1.5.tar.gz.
File metadata
- Download URL: py-gen-mur-1.1.5.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d76573d6bcffad145190636b299be37fb5fbc12f662475ef55f3a4826702655
|
|
| MD5 |
7e13582d44814d572b7ec79cf0dd5c83
|
|
| BLAKE2b-256 |
58d892657dd550c54a551fc224819096f891c428c776c97a97816b28b8bf6ec4
|
File details
Details for the file py_gen_mur-1.1.5-py3-none-any.whl.
File metadata
- Download URL: py_gen_mur-1.1.5-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cdd1befa13d11ba48a8b0592a5b7d1276b39bfd6422dfc4fd6b178f5860f2fe
|
|
| MD5 |
199cf0595c91902b2afd00d2092f9886
|
|
| BLAKE2b-256 |
eeff66252e5a5e1bbdaf32cdcdb8fb94d93f8e6f8438d1c534e222b255bae786
|