pygmlib
GMLib项目的python绑定,利用pybind11进行绑定
已经通过测试的环境
| 操作系统 | CPU | python版本 |
|---|---|---|
| Windows11 | i5-12500H | 3.9 |
| Windows11 | i5-12500H | 3.10 |
1 快速开始
1.1 通过pypi安装(推荐)
pip install pygmlib
1.2 通过源码包安装(推荐)
在pypi主页下载pygmlib项目的源码包并解压
- 运行
pip install ./pygmlib
1.3 通过github项目安装
- 克隆仓库
git clone https://github.com/oldprincess/py-gmlib.git
- 获取子模块
cd py-gmlib
git submodule update --init --recursive
cd ..
- pip安装pygmlib
pip install ./pygmlib
2 支持的密码算法
- SM3
- SM4: ECB, CBC, CFB, OFB, CTR, GCM
- AES: ECB, CBC, CFB, OFB, CTR, GCM
3 使用样例
下面的样例实现SM4算法ECB模式的加密和解密功能,并校验正确性
import pygmlib
sm4_key = bytes(16) # 16 bytes ZERO
sm4_pt = bytes(16) # 16 bytes ZERO
# sm4 ecb encrypt
sm4e = pygmlib.cipher.Sm4EcbEncryptor(sm4_key)
ct = sm4e.update(sm4_pt)
ct += sm4e.final()
# sm4 ecb decrypt
sm4d = pygmlib.cipher.Sm4EcbDecryptor(sm4_key)
pt = sm4d.update(ct)
pt += sm4d.final()
assert pt == sm4_pt
# key: 00000000000000000000000000000000
# pt : 00000000000000000000000000000000
# ct : 9f1f7bff6f5511384d9430531e538fd3
print("key:", sm4_key.hex())
print("pt :", sm4_pt.hex())
print("ct :", ct.hex())
Metadata
Release files for pygmlib 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pygmlib-1.0.0.tar.gz | 220.5 kB | Without provenance | Details for pygmlib-1.0.0.tar.gz |
Release files / pygmlib-1.0.0.tar.gz
| Download URL | pygmlib-1.0.0.tar.gz |
|---|---|
| Size | 220.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
626d8e60b64baead4bf673ce305ce2a84739849233d02c504a3855eb5f5a4028
|
|
BLAKE2b-256 checksum How to use checksums |
0bdc73f46891b6c884484c8ed5a6e0b9cec4748b5a8d073e8718bd432b11bd09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.11
|
Security for pygmlib 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.