A comprehensive encryption tool supporting multiple algorithms with GUI and CLI
Project description
加密工具 (CryptoTool)
这是一个基于Python的加密工具,提供了多种加密算法的实现,包括AES对称加密、RSA非对称加密、混合加密方案、哈希计算和Base64编码/解码。支持图形用户界面 (GUI) 和命令行接口 (CLI),并能处理大文件(通过分块加密)。
功能特点
- AES、RSA、混合 加密/解密 (支持文件和文本)
- SHA256 哈希计算
- Base64 编码/解码
- 密钥管理 (生成、吊销、列表 - 列表功能待实现)
- 图形用户界面 (GUI)
- 命令行接口 (CLI)
- 支持大文件分块处理 (由核心逻辑实现,具体看实现细节)
安装
通过PyPI安装(推荐)
pip install huawuque-cryptool
从源码安装
- 克隆项目到本地:
git clone https://github.com/huawuque/cryptool.git
cd cryptool
- 创建并激活虚拟环境:
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
- 安装依赖:
pip install -r requirements.txt
# 如果需要,也可以直接安装本包
# pip install .
使用方法
图形用户界面 (GUI)
安装后,如果您想使用图形界面,可以运行:
# (需要系统已正确配置Python环境)
cryptool-gui
(注意:如果上述命令无效,可能需要检查您的Python环境路径配置,或者直接运行Python脚本 python -m cryptool.gui.main_window)
命令行接口 (CLI)
安装后,您可以通过cryptool命令在命令行中使用该工具。
基本用法: cryptool <command> [options]
命令列表:
key: 密钥管理generate -t <aes|rsa>: 生成指定类型的密钥。revoke -t <aes|rsa> -i <key_id>: 吊销指定ID的密钥。list -t <aes|rsa>: 列出指定类型的密钥 (待实现)。
encrypt: 加密文件-a <aes|rsa|hybrid>: 指定加密算法。-i <input_file>: 指定输入文件路径。-o <output_file>: 指定输出文件路径。-k <key_id>: 指定使用的密钥ID (混合加密必需)。
decrypt: 解密文件-a <aes|rsa|hybrid>: 指定解密算法。-i <input_file>: 指定输入文件路径。-o <output_file>: 指定输出文件路径。-k <key_id>: 指定使用的密钥ID (混合解密必需)。
hash: 计算文件哈希-a <sha256>: 指定哈希算法。-i <input_file>: 指定输入文件路径。
base64: Base64 编码/解码encode -i <input_file> -o <output_file>: 对文件进行Base64编码。decode -i <input_file> -o <output_file>: 对文件进行Base64解码。
示例:
# 生成AES密钥
cryptool key generate -t aes
# 使用AES加密文件 (假设生成的密钥ID是 aes_key_123)
cryptool encrypt -a aes -i plain.txt -o encrypted.enc -k aes_key_123
# 使用AES解密文件
cryptool decrypt -a aes -i encrypted.enc -o decrypted.txt -k aes_key_123
# 计算文件SHA256哈希
cryptool hash -a sha256 -i important_doc.pdf
# Base64编码文件
cryptool base64 encode -i image.png -o image_base64.txt
Python代码中使用
(这部分可以保留或根据您的核心类 CryptoCore 的实际用法进行调整)
from cryptool.core.app import CryptoCore
# 初始化核心
core = CryptoCore()
# 生成AES密钥
key_id = core.generate_key('aes')
print(f"Generated AES key ID: {key_id}")
# 读取文件数据
with open('my_file.txt', 'rb') as f:
data_to_encrypt = f.read()
# 加密数据
encrypted_data = core.execute(
mode='encrypt',
algo='aes',
data=data_to_encrypt,
key_id=key_id
)
# 保存加密数据
with open('my_file.enc', 'wb') as f:
f.write(encrypted_data)
# 解密数据
decrypted_data = core.execute(
mode='decrypt',
algo='aes',
data=encrypted_data,
key_id=key_id
)
# 保存解密数据
with open('my_file_decrypted.txt', 'wb') as f:
f.write(decrypted_data)
print("File encryption and decryption example complete.")
# (确保在使用完后关闭 KeyManager)
core.key_manager.close()
配置
项目可能使用.env文件进行配置,或者有其他的配置机制(请根据实际情况说明)。
注意事项
- 密钥默认存储在项目根目录下的
keys目录(或数据库,请根据KeyManager实现说明)。 - 日志文件默认保存在
logs目录下。
许可证
MIT License
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 huawuque_cryptool-0.1.2.tar.gz.
File metadata
- Download URL: huawuque_cryptool-0.1.2.tar.gz
- Upload date:
- Size: 31.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce6be072e90ab308b21f86812fc2f4814bdbbf0d57d5eb0d1391db846b2c860c
|
|
| MD5 |
4d73062da071666287463cbfa09c0305
|
|
| BLAKE2b-256 |
6bdc752f88550a1ce3e9a123eea82f8669a79add7205b6cfa8a79f76a25ca74f
|
File details
Details for the file huawuque_cryptool-0.1.2-py3-none-any.whl.
File metadata
- Download URL: huawuque_cryptool-0.1.2-py3-none-any.whl
- Upload date:
- Size: 33.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
584efb0a254bc4b4a488b981098c6458018013bc80e75d05897ac6afbb8c697e
|
|
| MD5 |
27c8ea18f8c9043ca30a464c0a07efed
|
|
| BLAKE2b-256 |
7c6846ec17a2f7d99f281d6f039104502325a6ae19ad420fe024ad692b38919c
|