X27CN 代码混淆加密库 - Code obfuscation and encryption library
Project description
X27CN
X27CN 代码混淆加密库 - Code obfuscation and encryption library
安装
pip install x27cn
快速开始
import x27cn
# 加密
encrypted = x27cn.encrypt('Hello World')
print(encrypted) # <faee><38db>...
# 解密
decrypted = x27cn.decrypt(encrypted)
print(decrypted) # Hello World
# 使用自定义密钥
encrypted = x27cn.encrypt('敏感数据', key='mySecretKey')
decrypted = x27cn.decrypt(encrypted, key='mySecretKey')
文件混淆(前端代码保护)
Python API
import x27cn
# 混淆整个 HTML 文件(生成自解密页面)
x27cn.obfuscate_file('index.html') # 生成 index.obf.html
# 混淆 JavaScript 文件
x27cn.obfuscate_file('app.js') # 生成 app.obf.js
# 混淆 CSS 文件
x27cn.obfuscate_file('style.css') # 生成 style.obf.css
# 自定义输出路径和密钥
x27cn.obfuscate_file('app.html', 'dist/app.html', key='myKey')
命令行
# 混淆 HTML
x27cn obfuscate index.html
# 混淆 JS
x27cn obfuscate app.js dist/app.js
# 使用自定义密钥
x27cn obfuscate app.html --key=mySecretKey
# 加密文本
x27cn encrypt -t "Hello World"
# 解密文本
x27cn decrypt -t "<faee><38db>..."
混淆效果
原始 HTML:
<!DOCTYPE html>
<html>
<body>
<h1>Hello World</h1>
<script>alert('Secret!');</script>
</body>
</html>
混淆后:
<!DOCTYPE html>
<html>
<body>
<script>
(function(){var _$='<9525><0d5b>...';var _k=[0x78,0x32,...];...})();
</script>
</body>
</html>
浏览器加载混淆后的文件会自动解密并正常显示原始内容。
内联混淆
import x27cn
html = '''
<html>
<style>body { color: red; }</style>
<script>alert('hello');</script>
</html>
'''
# 只混淆内联 JS
result = x27cn.obfuscate_inline_js(html)
# 只混淆内联 CSS
result = x27cn.obfuscate_inline_css(html)
API 参考
基础加密/解密
# 标准格式(<xxxx> 标签)
encrypted = x27cn.encrypt('text')
decrypted = x27cn.decrypt(encrypted)
# 纯十六进制格式
hex_encrypted = x27cn.encrypt_hex('text')
decrypted = x27cn.decrypt_hex(hex_encrypted)
# Base64 格式
b64_encrypted = x27cn.encrypt_base64('text')
decrypted = x27cn.decrypt_base64(b64_encrypted)
文件混淆
# 混淆整个文件
x27cn.obfuscate_file(input_path, output_path=None, key='x27cn2026')
# 混淆 HTML 字符串
x27cn.obfuscate_html(html_content, key='x27cn2026')
# 混淆 JS 字符串
x27cn.obfuscate_js(js_content, key='x27cn2026')
# 混淆 CSS 字符串
x27cn.obfuscate_css(css_content, key='x27cn2026')
密钥管理
# 使用默认密钥
x27cn.encrypt('data') # 使用 'x27cn2026'
# 自定义密钥
x27cn.encrypt('data', key='myKey')
# 生成随机密钥
random_key = x27cn.generate_key(16) # 16 字符随机密钥
算法说明
X27CN v2 使用以下加密步骤:
- 密钥扩展 - 将密钥扩展为 256 字节
- S-Box 替换 - 非线性字节替换
- 位旋转 - 循环左移 5 位
- 状态混合 - 使用累积状态值混淆
安全说明
X27CN 设计用于代码混淆,不是密码学安全的加密算法。
适用场景:
- 前端代码混淆保护
- API 响应混淆
- 配置文件保护
- 防止代码被轻易复制
不适用场景:
- 密码存储(请使用 bcrypt/argon2)
- 敏感数据加密(请使用 AES-256)
- 通信加密(请使用 TLS)
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
x27cn-1.1.0.tar.gz
(10.1 kB
view details)
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
x27cn-1.1.0-py3-none-any.whl
(10.1 kB
view details)
File details
Details for the file x27cn-1.1.0.tar.gz.
File metadata
- Download URL: x27cn-1.1.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebfdedd5c587befad38fcb567293e9629e701bcaf507de5592113ef23a5deac3
|
|
| MD5 |
5fbc974dc85edc9912cf4ec2aaeea316
|
|
| BLAKE2b-256 |
1d6f44e52b6bcb0e12404edc2313f493b10da2e3de5faaf325274e67e0dded73
|
File details
Details for the file x27cn-1.1.0-py3-none-any.whl.
File metadata
- Download URL: x27cn-1.1.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d946441fdb461372660f7a94834c22262f52feb372b99e769fcb13ea32bc1127
|
|
| MD5 |
82ae696802e004910037af95708d4d38
|
|
| BLAKE2b-256 |
407caffdc56380f07ccc19283805005857390f3f10067a0df919c8041f9ac615
|