Metadata-Version: 2.4
Name: darren_utils
Version: 0.1.5
Summary: 一个功能丰富的工具包
Home-page: https://github.com/Darren5211314
Author: Darren
Author-email: Darren <2775856@qq.com>
License: MIT
Project-URL: Homepage, https://github.com/Darren5211314
Project-URL: Repository, https://github.com/Darren5211314
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Requires-Dist: requests
Requires-Dist: pyarmor>=9.0
Requires-Dist: cryptography
Requires-Dist: gmssl
Requires-Dist: send2trash
Requires-Dist: wmi
Dynamic: author
Dynamic: home-page
Dynamic: requires-python

# darren_utils

一个功能丰富的Python工具库，包含加密解密、哈希计算、HTTP请求、字符串处理、时间处理、文件操作和硬件信息获取等多种实用功能。

## 安装

```bash
pip install darren_utils
```

## 功能模块

### 网络工具 (darren_utils)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| get_public_ip | 获取公网IP信息 | ip (str): IP地址, source (int): 获取IP信息的源，默认为10 | dict: IP信息字典 |
| url_get_domain | 获取URL的域名 | url (str): URL字符串 | str: 域名 |
| get_jsonp | 解析JSONP字符串并返回JSON对象 | text (str): JSONP字符串 | dict: 解析后的JSON对象 |

### 硬件信息 (darren_devices)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| GetHardwareInformation | 硬件信息类，用于获取计算机硬件信息 | 无 | GetHardwareInformation对象 |
| get_devices_id | 获取设备指纹ID（基于硬件信息生成的MD5哈希值） | 无 | str: 设备指纹ID |
| GetHardwareInformation.get_board_id | 获取主板序列号 | 无 | str: 主板序列号 |
| GetHardwareInformation.get_bios_id | 获取BIOS序列号 | 无 | str: BIOS序列号 |
| GetHardwareInformation.get_cpu_id | 获取CPU序列号 | 无 | str: CPU序列号 |
| GetHardwareInformation.get_physical_disk_id | 获取硬盘序列号 | 无 | str: 硬盘序列号 |
| GetHardwareInformation.get_gpu_info | 获取显卡信息 | 无 | str: 显卡信息 |
| GetHardwareInformation.get_system_info | 获取系统版本信息 | 无 | str: 系统版本信息 |
| GetHardwareInformation.get_system_uuid | 获取系统UUID | 无 | str: 系统UUID |
| GetHardwareInformation.get_all | 获取所有硬件信息 | 无 | str: 所有硬件信息的文本表示 |
| GetHardwareInformation.get_devices_id | 获取设备指纹ID（基于硬件信息生成的MD5哈希值） | 无 | str: 设备指纹ID |

### 文件操作 (darren_file)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| file_exists | 检查文件是否存在 | file_path (str): 文件路径 | bool: 文件存在返回True，否则返回False |
| dir_exists | 检查目录是否存在 | dir_path (str): 目录路径 | bool: 目录存在返回True，否则返回False |
| file_is_use | 检查文件是否被占用 | file_path (str): 文件路径 | bool: 文件被占用返回True，否则返回False |
| file_open | 打开文件并返回文件句柄 | file_path (str): 文件路径, mode (str): 文件打开模式，默认为'r'(只读) | file object or int: 成功时返回文件句柄，失败时返回-1 |
| file_execute | 执行文件，如运行exe程序或用默认程序打开文件 | file_path (str): 文件路径 | subprocess.Popen or bool or int: 成功时返回进程对象或True，失败时返回-1 |
| file_locate | 在文件管理器中定位文件，打开文件所在目录并选中该文件 | file_path (str): 文件路径 | bool or int: 成功时返回True，失败时返回-1 |
| file_copy | 复制文件 | src_path (str): 源文件路径, dest_path (str): 目标文件路径, overwrite (bool): 是否覆盖已存在的文件，默认为False | bool or int: 成功时返回True，失败时返回-1 |
| file_rename | 重命名文件 | old_name (str): 原文件名, new_name (str): 新文件名 | bool or int: 成功时返回True，失败时返回-1 |
| file_enumerate | 枚举某个目录下的指定类型文件 | directory (str): 欲寻找的目录, pattern (str): 欲寻找的文件名(如果寻找全部文件可以填入*.*，或*.txt只找txt文件, 多个后缀中间用"|"隔开), with_path (bool): 是否带路径(默认为假； 真=带目录路径，如C:\\012.txt； 假=不带，如 012.txt), sort_alpha (bool): 是否按字母排序(默认为假；真=按字母a-z排序 假=不排序), recursive (bool): 是否遍历子目录(默认为假) | list or int: 成功时返回文件列表，失败时返回-1 |
| file_size | 获取文件大小 | file_path (str): 文件路径, unit (str): 返回大小的单位(B、KB、MB、GB)，默认为M | str or int: 成功时返回格式化的文件大小字符串，失败时返回-1 |
| file_get_extension | 获取文件扩展名 | file_path (str): 文件路径 | str or int: 成功时返回文件扩展名（如：.jpg），没有扩展名时返回空字符串，失败时返回-1 |
| file_get_directory | 获取文件所在目录路径 | file_path (str): 文件路径 | str or int: 成功时返回文件所在目录路径，失败时返回-1 |
| file_get_info | 获取文件信息 | file_path (str): 文件路径 | dict or int: 成功时返回包含文件信息的字典，失败时返回-1 |
| file_get_name | 获取文件名 | file_path (str): 文件路径, with_extension (bool): 是否带后缀，默认为False，不带后缀；True为带后缀 | str or int: 成功时返回文件名，失败时返回-1 |
| file_delete | 删除文件 | file_path (str): 文件路径, to_trash (bool): 是否删除到回收站，默认为True（删除到回收站）；False为彻底删除 | bool or int: 成功时返回True，失败时返回-1 |

### 字符串处理 (darren_string)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| string_random_string | 生成随机字符串 | length (int): 字符串长度 | str: 随机字符串 |
| string_get_between | 获取两个字符串之间的内容 | text (str): 原始文本, start (str): 起始字符串, end (str): 结束字符串 | str: 两个字符串之间的内容 |
| string_get_left | 获取字符串左侧内容 | text (str): 原始文本, separator (str): 分隔符 | str: 分隔符左侧的内容 |
| string_get_right | 获取字符串右侧内容 | text (str): 原始文本, separator (str): 分隔符 | str: 分隔符右侧的内容 |

### 时间处理 (darren_time)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| time_get_timestamp | 获取当前时间戳 | 无 | int: 当前时间戳 |
| time_random_timestamp | 生成随机时间戳 | 无 | int: 随机时间戳 |
| time_format | 格式化时间戳 | timestamp (int): 时间戳, format_str (str): 格式化字符串 | str: 格式化后的时间字符串 |

### HTTP请求 (darren_http)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| darren_http | 发送HTTP请求 | url (str): 请求地址, method (str): 请求方法, headers (dict): 请求头, data (dict): 请求数据 | dict: 响应结果 |
| darren_http_proxy | 发送带代理的HTTP请求 | url (str): 请求地址, method (str): 请求方法, headers (dict): 请求头, data (dict): 请求数据, proxy (str): 代理地址 | dict: 响应结果 |

### 日志处理 (darren_utils)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| save_log | 保存日志 | log_content (str): 日志内容, log_file (str): 日志文件路径 | bool: 保存成功返回True，否则返回False |

### Cookie处理 (darren_http)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| cookie_dict_to_string | 将字典转换为Cookie字符串 | cookie_dict (dict): Cookie字典 | str: Cookie字符串 |
| cookie_string_to_dict | 将Cookie字符串转换为字典 | cookie_string (str): Cookie字符串 | dict: Cookie字典 |
| cookie_merge | 合并两个Cookie字典 | cookie_dict1 (dict): 第一个Cookie字典, cookie_dict2 (dict): 第二个Cookie字典 | dict: 合并后的Cookie字典 |

### 哈希算法 (darren_hash)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| hash_md5_string | 计算字符串的MD5哈希值 | text (str): 输入字符串 | str: MD5哈希值 |
| hash_md5_bytes | 计算字节数组的MD5哈希值 | data (bytes): 输入字节数组 | str: MD5哈希值 |
| hash_sha1_string | 计算字符串的SHA1哈希值 | text (str): 输入字符串 | str: SHA1哈希值 |
| hash_sha1_bytes | 计算字节数组的SHA1哈希值 | data (bytes): 输入字节数组 | str: SHA1哈希值 |
| hash_sha256_string | 计算字符串的SHA256哈希值 | text (str): 输入字符串 | str: SHA256哈希值 |
| hash_sha256_bytes | 计算字节数组的SHA256哈希值 | data (bytes): 输入字节数组 | str: SHA256哈希값 |
| hash_sha512_string | 计算字符串的SHA512哈希值 | text (str): 输入字符串 | str: SHA512哈希값 |
| hash_sha512_bytes | 计算字节数组的SHA512哈希值 | data (bytes): 输入字节数组 | str: SHA512哈希값 |
| hash_crc32_int | 计算数据的CRC32值 | data (bytes): 输入数据 | int: CRC32值 |

### HMAC算法 (darren_hmac)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| hmac_md5 | 使用MD5算法计算HMAC | key (str): 密钥, message (str): 消息 | str: HMAC值 |
| hmac_sha1 | 使用SHA1算法计算HMAC | key (str): 密钥, message (str): 消息 | str: HMAC值 |
| hmac_sha256 | 使用SHA256算法计算HMAC | key (str): 密钥, message (str): 消息 | str: HMAC值 |
| hmac_sha512 | 使用SHA512算法计算HMAC | key (str): 密钥, message (str): 消息 | str: HMAC值 |
| hmac_sha3_256 | 使用SHA3-256算法计算HMAC | key (str): 密钥, message (str): 消息 | str: HMAC值 |
| hmac_sha3_512 | 使用SHA3-512算法计算HMAC | key (str): 密钥, message (str): 消息 | str: HMAC值 |

### CRC32算法 (darren_rc4)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| hash_crc32_string | 计算字符串的CRC32值 | text (str): 输入字符串 | int: CRC32값 |

### RC4加密 (darren_rc4)

| 方法名 | 描述 | 参数 | 返回값 |
|--------|------|------|--------|
| rc4_encrypt_string | 使用RC4算法加密字符串 | key (str): 密钥, plaintext (str): 明文 | str: 加密后的字符串 |
| rc4_decrypt_string | 使用RC4算法解密字符串 | key (str): 密钥, ciphertext (str): 密文 | str: 解密后的字符串 |
| RC4 | RC4加密类 | key (bytes): 密钥 | RC4对象 |

### AES加密 (darren_aes)

| 方法名 | 描述 | 参数 | 返回값 |
|--------|------|------|--------|
| AESCipher | AES加密类 | key (str): 密钥 | AESCipher对象 |
| aes_encrypt_string | 使用AES算法加密字符串 | key (str): 密钥, plaintext (str): 明文 | str: 加密后的字符串 |
| aes_decrypt_string | 使用AES算法解密字符串 | key (str): 密钥, ciphertext (str): 密文 | str: 解密后的字符串 |

### DES加密 (darren_des)

| 方法名 | 描述 | 参数 | 返回값 |
|--------|------|------|--------|
| DESCipher | DES加密类 | key (str): 密钥 | DESCipher对象 |
| des_encrypt_string | 使用DES算法加密字符串 | key (str): 密钥, plaintext (str): 明文 | str: 加密后的字符串 |
| des_decrypt_string | 使用DES算法解密字符串 | key (str): 密钥, ciphertext (str): 密文 | str: 解密后的字符串 |

### 3DES加密 (darren_3des)

| 方法名 | 描述 | 参数 | 返回값 |
|--------|------|------|--------|
| TDESCipher | 3DES加密类 | key (str): 密钥 | TDESCipher对象 |
| tdes_encrypt_string | 使用3DES算法加密字符串 | key (str): 密钥, plaintext (str): 明文 | str: 加密后的字符串 |
| tdes_decrypt_string | 使用3DES算法解密字符串 | key (str): 密钥, ciphertext (str): 密文 | str: 解密后的字符串 |

### JavaScript兼容3DES加密 (darren_3des_js)

| 方法名 | 描述 | 参数 | 返回값 |
|--------|------|------|--------|
| TDESCipher_JS | JavaScript兼容的3DES加密类 | key (str): 密钥 | TDESCipher_JS对象 |
| tdes_encrypt_string_js | 使用JavaScript兼容的3DES算法加密字符串 | key (str): 密钥, plaintext (str): 明文 | str: 加密后的字符串 |
| tdes_decrypt_string_js | 使用JavaScript兼容的3DES算法解密字符串 | key (str): 密钥, ciphertext (str): 密文 | str: 解密后的字符串 |

### SM2加密 (darren_sm2)

| 方法名 | 描述 | 参数 | 返回값 |
|--------|------|------|--------|
| SM2Cipher | SM2加密类 | 无 | SM2Cipher对象 |
| sm2_generate_keypair | 生成SM2密钥对 | 无 | tuple: (私钥, 公钥) |
| sm2_encrypt_string | 使用SM2算法加密字符串 | public_key (str): 公钥, plaintext (str): 明文 | str: 加密后的字符串 |
| sm2_decrypt_string | 使用SM2算法解密字符串 | private_key (str): 私钥, ciphertext (str): 密文 | str: 解密后的字符串 |
| sm2_sign | 使用SM2算法签名 | private_key (str): 私钥, message (str): 消息 | str: 签名 |
| sm2_verify | 使用SM2算法验证签名 | public_key (str): 公钥, message (str): 消息, signature (str): 签名 | bool: 验证成功返回True，否则返回False |

### SM3哈希 (darren_sm3)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| hash_sm3_string | 计算字符串的SM3哈希值 | text (str): 输入字符串 | str: SM3哈希值 |
| hash_sm3_bytes | 计算字节数组的SM3哈希值 | data (bytes): 输入字节数组 | str: SM3哈希값 |

### SM4加密 (darren_sm4)

| 方法名 | 描述 | 参数 | 返回값 |
|--------|------|------|--------|
| SM4Cipher | SM4加密类 | key (str): 密钥 | SM4Cipher对象 |
| sm4_encrypt_string | 使用SM4算法加密字符串 | key (str): 密钥, plaintext (str): 明文 | str: 加密后的字符串 |
| sm4_decrypt_string | 使用SM4算法解密字符串 | key (str): 密钥, ciphertext (str): 密文 | str: 解密后的字符串 |

### RSA加密 (darren_rsa)

| 方法名 | 描述 | 参数 | 返回값 |
|--------|------|------|--------|
| RSACipher | RSA加密类 | 无 | RSACipher对象 |
| rsa_generate_keypair | 生成RSA密钥对 | key_size (int): 密钥长度 | tuple: (私钥, 公钥) |
| rsa_encrypt_string | 使用RSA算法加密字符串 | public_key (str): 公钥, plaintext (str): 明文, padding (str): 填充方式 | str: 加密后的字符串 |
| rsa_decrypt_string | 使用RSA算法解密字符串 | private_key (str): 私钥, ciphertext (str): 密文, padding (str): 填充方式 | str: 解密后的字符串 |
| rsa_sign | 使用RSA算法签名 | private_key (str): 私钥, message (str): 消息, hash_algorithm (str): 哈希算法 | str: 签名 |
| rsa_verify | 使用RSA算法验证签名 | public_key (str): 公钥, message (str): 消息, signature (str): 签名, hash_algorithm (str): 哈希算法 | bool: 验证成功返回True，否则返回False |

### JavaScript兼容RSA加密 (js_rsa)

| 方法名 | 描述 | 参数 | 返回值 |
|--------|------|------|--------|
| JSRSA | JavaScript兼容的RSA加密类 | 无 | JSRSA对象 |
| js_rsa_generate_keypair | 生成JavaScript兼容的RSA密钥对 | key_size (int): 密钥长度 | tuple: (私钥, 公钥) |
| js_rsa_public_encrypt | 使用公钥加密 | public_key (str): 公钥, plaintext (str): 明文, padding (int or AsymmetricPadding): 填充方式 | str: 加密后的字符串 |
| js_rsa_private_decrypt | 使用私钥解密 | private_key (str): 私钥, ciphertext (str): 密文, padding (int or AsymmetricPadding): 填充方式 | str: 解密后的字符串 |
| js_rsa_private_encrypt | 使用私钥加密 | private_key (str): 私钥, plaintext (str): 明文, padding (int or AsymmetricPadding): 填充方式 | str: 加密后的字符串 |

## 使用示例

```python
import darren_utils

# 文件操作示例
if darren_utils.file_exists("example.txt"):
    print("文件存在")
    
files = darren_utils.file_enumerate(".", "*.py")
print("Python文件列表:", files)

# 字符串处理示例
random_str = darren_utils.string_random_string(10)
print("随机字符串:", random_str)

# 时间处理示例
timestamp = darren_utils.time_get_timestamp()
print("当前时间戳:", timestamp)

# HTTP请求示例
response = darren_utils.darren_http("https://httpbin.org/get")
print("HTTP响应:", response)

# 哈希计算示例
md5_hash = darren_utils.hash_md5_string("hello world")
print("MD5哈希值:", md5_hash)

# 加密解密示例
encrypted = darren_utils.aes_encrypt_string("mykey", "hello world")
decrypted = darren_utils.aes_decrypt_string("mykey", encrypted)
print("AES加密解密:", decrypted)

# 硬件信息示例
device_id = darren_utils.get_devices_id()
print("设备指纹ID:", device_id)

# 获取详细硬件信息
hardware_info = darren_utils.GetHardwareInformation()
print("主板序列号:", hardware_info.get_board_id())
print("CPU序列号:", hardware_info.get_cpu_id())
print("系统信息:", hardware_info.get_system_info())
```

## 许可证

MIT
