Skip to main content

python实现的国密SM2/SM3/SM4算法库

Project description

gd_sm

软件说明

这是一个python实现的国密算法库,按照国密规范实现了sm2/sm3/sm4算法,其中sm2的功能主要是参考gmssl 库,在其基础上进行了一定的完善。 sm3和sm4是利用了cryptography库,采用这个库进行了sm3和sm4运算,这里只是对其进行了简单封装。

每个模块实现了以下功能,在使用这些函数或方法时,传入的数据需要是16进制字符串或者bytes格式(传入bytes格式也会被转成16进制字符串处理), 返回的数据均为16进制字符串,建议调用的时候统一使用16进制字符串,为了方便,最好统一成16进制字符串小写格式。

  • sm2:
    • sign: 使用sm2私钥进行签名
    • verify: 使用sm2公钥进行验签
    • encrypt: 使用sm2公钥进行加密
    • decrypt: 使用sm2私钥进行加密
    • private_key_export_pubkey: 通过私钥导出公钥
    • nor_compressed_pubkey: 输出公钥的非压缩形式
    • compressed_pubkey: 输出公钥的压缩形式
  • sm3:
    • sm3_hash: 计算sm3 hash值
    • check_sm3: 校验sm3 hash值是否正确
  • sm4:
    • encrypt: sm4加密,支持ecb/cbc模式,不填充或者采用pkcs7 padding填充
    • decrypt: sm4解密,支持ecb/cbc模式,不填充或者采用pkcs7 padding填充

使用说明

使用pip安装本项目pip install gd_sm,在代码中使用from gd_sm import *语句引用

也可以clone本项目到本地,在项目根目录下执行pip install .安装

示例

参考本项目的test下的示例代码example.py

打包上传pypi

  • 首先安装flit、twine
pip install flit twine
  • 修改pyproject.toml文件中的版本号、依赖等相关信息,打包前要先使用pytest运行test目录下的test_*.py文件确认代码没有问题

  • 并将代码提交,保存目录下没有未提交的文件

  • 在项目根目录下执行flit build命令打包,生成dist文件夹,里面包含打包后的文件,执行twine upload dist/*命令上传到pypi

注意事项

  • 目前只支持sm2/sm3/sm4的部分功能,后续会逐步支持更多的功能

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gd_sm-1.0.4.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gd_sm-1.0.4-py2.py3-none-any.whl (10.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file gd_sm-1.0.4.tar.gz.

File metadata

  • Download URL: gd_sm-1.0.4.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for gd_sm-1.0.4.tar.gz
Algorithm Hash digest
SHA256 c34e02849f756d38d5b02be070baa6f9ba939a169567ec4aee301e3272c7c671
MD5 d827b6b13ff7273989cee40ce8b51eac
BLAKE2b-256 f5f9a2f869bf8210185950de1fd2188fb2e1a05da455e75035c0477f09877198

See more details on using hashes here.

File details

Details for the file gd_sm-1.0.4-py2.py3-none-any.whl.

File metadata

  • Download URL: gd_sm-1.0.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for gd_sm-1.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 350d75ae9bc89d7e2589def3ec74e79b1a9ac147dee3f89ad83c6543910d0e62
MD5 8cf0643e09619682d6d8da595d9acfd9
BLAKE2b-256 7e0bd616cc5718c8a322e43f9cae630431d6c9ba055ea32a3b431477c1d641f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page