Metadata-Version: 2.4
Name: taiji_hasp
Version: 0.3.6
Summary: A Python wrapper for HASP license protection
Author: kkzhang
Author-email: kkzhang <kkzhang3@hotmail.com>
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Dynamic: author
Dynamic: requires-python

# python_hasp

Taiji HASP 加密锁的 Python 封装。

## 构建

```bash
python setup_build.py build_ext --inplace
python -m build --wheel
```

## 使用

### 授权信息

```python
from taiji_hasp import TaiJiHasp

hasp = TaiJiHasp(6)                # 新接口：TaiJiHasp(feature_id)
# hasp = TaiJiHasp(vendor_code, 6) # 旧接口：TaiJiHasp(vendorCode, feature_id)

print("login status =", hasp.login())
hasp.read()
print("expire date =", hasp.get_expire_date())
print("is expired =", hasp.is_expired())
print("MPC instance count =", hasp.get_mpc_instance_count())
hasp.logout()
```

### 加密 / 解密（模块级接口）

```python
from taiji_hasp import encrypt, decrypt

feature_id = 6
plaintext = b"0123456789abcdef"          # 至少 16 字节

ciphertext = encrypt(feature_id, plaintext)
restored = decrypt(feature_id, ciphertext)
assert restored == plaintext
```

### 加密 / 解密（TaiJiHasp 方法）

```python
from taiji_hasp import TaiJiHasp

hasp = TaiJiHasp(6)
ciphertext = hasp.encrypt(b"0123456789abcdef")
plaintext = hasp.decrypt(ciphertext)
```

### 在 Cython 中调用（cimport）

将 `taiji_hasp.pxd` 放入 Python 环境后即可在其它 Cython 模块中 cimport：

```python
from cython.cimports.taiji_hasp.taiji_hasp import (
    hasp_encrypt_bytes,
    hasp_decrypt_bytes,
    check_only,
    check_and_decrypt,
)
```

## 注意事项

- 数据长度必须 >= 16 字节（`HASP_MIN_BLOCK_SIZE`），否则抛出 `ValueError`；HASP 也会返回 `HASP_TOO_SHORT`。
- 解密必须使用与加密相同的 `feature_id`。
- 数据为空或类型不是 bytes / bytearray / memoryview 时抛出 `TypeError` / `ValueError`。
- 登录失败、授权无效或加密 / 解密失败时抛出 `RuntimeError`，授权过期时错误码为 `-100`。
- `encrypt` / `decrypt` 内部自带 login -> 过期检查 -> 加解密 -> logout，无需事先调用 `login()`。
