GmSSL Python API
Project description
GmSSL-Python
简介
本项目是GmSSL密码库的Python语言封装。GmSSL-Python目前提供了随机数生成器、SM3哈希、SM3消息认证码(HMAC-SM3)、SM4加密(包括分组加密和CBC/CTR/GCM加密模式)、ZUC加密、SM2加密/签名等功能,可以覆盖目前国密算法主要应用开发场景。
编译和安装
GmSSL-Java依赖GmSSL项目,在编译前需要先在系统上编译、安装并测试通过GmSSL库及工具。请在https://github.com/guanzhi/GmSSL 项目上下载最新的GmSSL代码,并完成编译、测试和安装。
下载最新的GmSSL-Python代码 GmSSL-Python-main.zip,解压缩,进入源代码目录。
首先创建源码安装包
python setup.py sdist
本地安装
python setup.py install
在安装过程中会产生deprecated
警告,对于Python 3.11及之前的版本可忽略此警告,并可以顺利编译完成。
运行测试
$ python -m unittest
..........
----------------------------------------------------------------------
Ran 10 tests in 0.256s
OK
上面的输出表明测试通过。
编写一个简单的测试程序sm3.py
from gmssl import *
sm3 = Sm3()
sm3.update(b'abc')
dgst = sm3.digest()
print("sm3('abc') : " + dgst.hex())
执行这个程序
$ python demo.py
sm3('abc') : 66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0
可以看到运行成功。通过gmssl
命令行验证输出是正确的
echo -n abc | gmssl sm3
可以看到输出相同的SM3哈希值
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
gmssl_python-2.1.0.tar.gz
(10.9 kB
view details)
Built Distribution
File details
Details for the file gmssl_python-2.1.0.tar.gz
.
File metadata
- Download URL: gmssl_python-2.1.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5f2bf4b7bc702436c2d2b9aa11cf825750b6d98d48e443be382d1b187b60e0c |
|
MD5 | fca05add7b6396969d68edb0cdfc4b6b |
|
BLAKE2b-256 | b3e0cf4fcf5a84c29c27ecec43f4f5f5410d8f30719a92f24f38ddcaf158c50f |
File details
Details for the file gmssl_python-2.1.0-py3-none-any.whl
.
File metadata
- Download URL: gmssl_python-2.1.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b1119ad9246ac652c641274964c20b2d460da6b6b1b295602e20b576d240bbb |
|
MD5 | 4025e2b0b392a299486ca702258c2adf |
|
BLAKE2b-256 | d9971ad41d9682c2fceb119ce298d087d728d86fee14423d48da6704f223ef52 |