Skip to main content

Tongsuo Python SDK

Project description

tongsuo-python-sdk

Tongsuo-Python-SDK基于Tongsuo密码库, 为Python应用提供密码学原语和安全传输协议的支持,目前以支持中国商用密码算法和安全协议为主。

SM2签名和验签,详见sm2_sign_verify.py

from tongsuopy.crypto import hashes, serialization
from tongsuopy.crypto.asymciphers import ec

msg = b"hello"
key = ec.generate_private_key(ec.SM2())

pem = key.public_key().public_bytes(
    encoding=serialization.Encoding.PEM,
    format=serialization.PublicFormat.SubjectPublicKeyInfo,
)
pubkey = serialization.load_pem_public_key(pem)

signature = key.sign(msg, ec.ECDSA(hashes.SM3()))
pubkey.verify(signature, msg, ec.ECDSA(hashes.SM3()))

SM3杂凑,详见sm3.py

from tongsuopy.crypto import hashes

h = hashes.Hash(hashes.SM3())
h.update(b"abc")
res = h.finalize()

SM4-CBC加密,详见sm4_cbc.py

from tongsuopy.crypto.ciphers import Cipher, algorithms, modes

c = Cipher(algorithms.SM4(key), modes.CBC(iv))
enc = c.encryptor()
ciphertext = enc.update(plaintext)
ciphertext += enc.finalize()

SM4-GCM加密,详见sm4_gcm.py

from tongsuopy.crypto.ciphers import Cipher, algorithms, modes

c = Cipher(algorithms.SM4(key), modes.GCM(iv))

enc = c.encryptor()
enc.authenticate_additional_data(aad)
ciphertext = enc.update(plaintext)
ciphertext += enc.finalize()

安装

pip install tongsuopy

要求Python >= 3.6。

功能特性

  • 支持SM2签名和验签
  • 支持SM3杂凑算法
  • 支持SM4加解密,包括ECB、CBC、OFB、CFB、CTR模式
  • 支持SM4-GCM和SM4-CCM
  • [TODO] TLCP协议支持

交流群

欢迎加入铜锁社区交流群,使用钉钉扫描二维码或者钉钉内搜索群号44810299。

铜锁社区交流群

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

tongsuopy-1.0.1-pp39-pypy39_pp73-win_amd64.whl (1.3 MB view details)

Uploaded PyPyWindows x86-64

tongsuopy-1.0.1-pp39-pypy39_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.8 MB view details)

Uploaded PyPymanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

tongsuopy-1.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

tongsuopy-1.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (1.8 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64manylinux: glibc 2.24+ x86-64

tongsuopy-1.0.1-pp39-pypy39_pp73-macosx_10_12_x86_64.whl (1.5 MB view details)

Uploaded PyPymacOS 10.12+ x86-64

tongsuopy-1.0.1-pp38-pypy38_pp73-win_amd64.whl (1.3 MB view details)

Uploaded PyPyWindows x86-64

tongsuopy-1.0.1-pp38-pypy38_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.8 MB view details)

Uploaded PyPymanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

tongsuopy-1.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

tongsuopy-1.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (1.8 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64manylinux: glibc 2.24+ x86-64

tongsuopy-1.0.1-pp38-pypy38_pp73-macosx_10_12_x86_64.whl (1.5 MB view details)

Uploaded PyPymacOS 10.12+ x86-64

tongsuopy-1.0.1-cp36-abi3-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.6+Windows x86-64

tongsuopy-1.0.1-cp36-abi3-win32.whl (1.2 MB view details)

Uploaded CPython 3.6+Windows x86

tongsuopy-1.0.1-cp36-abi3-musllinux_1_1_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.6+musllinux: musl 1.1+ x86-64

tongsuopy-1.0.1-cp36-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.6+manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

tongsuopy-1.0.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.6+manylinux: glibc 2.17+ x86-64

tongsuopy-1.0.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.6+manylinux: glibc 2.17+ x86-64manylinux: glibc 2.24+ x86-64

tongsuopy-1.0.1-cp36-abi3-macosx_10_12_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.6+macOS 10.12+ x86-64

tongsuopy-1.0.1-cp36-abi3-macosx_10_12_universal2.whl (1.8 MB view details)

Uploaded CPython 3.6+macOS 10.12+ universal2 (ARM64, x86-64)

File details

Details for the file tongsuopy-1.0.1-pp39-pypy39_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-pp39-pypy39_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 0d7fe8af36922897f7430291424938127f29fc06a97c743728974f2fda6c2df9
MD5 72640d8e0b44ed3c4fae98ec0bbc31c3
BLAKE2b-256 6bd05563e654415c840fd6a0300d3086610231ac5a96be425c93cf3bab628600

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-pp39-pypy39_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-pp39-pypy39_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 616302d76e4affb7fb98598dd02944aa4608c41948e87998062a550c4b55d6f3
MD5 3baa12521e74bf3d9229c275a9b89b3b
BLAKE2b-256 9496b7dc518ebafcd755d109a9cf667c263268168e091776942f97c7bd8aba64

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d2663a6e2aea9ebfa8117c7382e52a43a8d03a5707cead430e2b36448cb91ac3
MD5 d15e51cedbd585aab2257288f8fcf8ae
BLAKE2b-256 df516c3b3d5eb703326d66cb184c77df1d521568984baf2a15402d0b47225094

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 5c68cd52cd3f21ca7281266b69f8b83615212b4daf6682af52ff1d11da413db8
MD5 5493fc3a574f138f62c8eba270b0da47
BLAKE2b-256 c7817f9cb1f780746aad176596a1bfd4470563efdb24e29de65c31dfa0fb8fea

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-pp39-pypy39_pp73-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-pp39-pypy39_pp73-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 17ad389f9ff655eca001175063f1674b468a4a586a1e635b6124b931b7bf39c6
MD5 a343fde06db727cd2a519963c58293b1
BLAKE2b-256 773c311fabf03ef864b6f5e56a4c118a9ea19634fd847d4abf21526965e13dc0

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-pp38-pypy38_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-pp38-pypy38_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 5f4b8048e2e9799b46e1848af31ce7a853af0f69a5f0757497f169e6d6a89367
MD5 b3f4dcf8061b127b2ca7a2095781c89d
BLAKE2b-256 3cd4ab6e6f15dc9a5ab104c9122c9072a2857cbd5ec64fc7798088974ca2ffac

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-pp38-pypy38_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-pp38-pypy38_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 73dae334d2cd462f84ec590741d75b4e80349b9cb0415edaffee98044eaea931
MD5 ca3532d67095e23d3655c607730288d6
BLAKE2b-256 11b3e53a7b4275082593fa983eefd4900457a4eb113afa503335ac50db1bf0ae

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 039e411cb245e4b737ca441c38b8b5e9be76b8b3b3843863495706c5d1f907dc
MD5 04f9df90435fc0b31f708f63d70a55d2
BLAKE2b-256 a4eb05d053107e085745a6028cfce83639e0db670d1c4e9367f235a15793a6ee

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 664811b1ea7f256cceb8bbd7c4fa0f97dcab48142793fbfbe43d3e0de0ed3abc
MD5 cba7dc77c68e5eef7d7da14113b1f785
BLAKE2b-256 a6e512e72f78744467e7cb9fbf7c956d62df97934005b54ca65e9c052890314c

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-pp38-pypy38_pp73-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-pp38-pypy38_pp73-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0ea2e8d4e8f3d1bd6944c1cc2de3d22d467e29f74d15c7e54834f5dec81f4237
MD5 8d4706a30aad78a28af2f6c6370e4df1
BLAKE2b-256 ac2e5c4cad46fd8c8b1683a41593b96a5fbbe257573af6ea328024c8ec48efed

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-cp36-abi3-win_amd64.whl.

File metadata

  • Download URL: tongsuopy-1.0.1-cp36-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.6+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for tongsuopy-1.0.1-cp36-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 178c1cefc16a929fe62b8f4cbaa6c8064e8106acaaa8283d895538f529ffa1e0
MD5 c3c08a9d9e4fe548e29295fc52d435b5
BLAKE2b-256 3a51cbcdf5b3f920305c24365d3d147b983b259ca3f716cafccdd9237ab21288

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-cp36-abi3-win32.whl.

File metadata

  • Download URL: tongsuopy-1.0.1-cp36-abi3-win32.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.6+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for tongsuopy-1.0.1-cp36-abi3-win32.whl
Algorithm Hash digest
SHA256 565e894878b8e34fd8a96ec27e43253a1a112025209a54de3b0c372f09ca98ae
MD5 9626f3ad064221cac523557de2f6dbd3
BLAKE2b-256 7e8e6011b4f9490b3bff7bc0f207f20666867134a5d4655a46d26d16cc3b457c

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-cp36-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 02b9cc2965b90cad208432bce0206579f574dc19e59192520e52515c42f08e95
MD5 07a072b5d61bdc2803817e958f04cd00
BLAKE2b-256 97b12aa58706306f6a83c83255ff0c384ff941c023ee3d04d7767049b37e7029

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-cp36-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-cp36-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 daabaf13e113af1e1ffca1b5e321da40273b64a0359f9c1b1146f1d9de06ccda
MD5 4cdd3bd9f5df9890e900b937a5865861
BLAKE2b-256 85411a9ad2277665b0aa185ce0ff08154c38015c95e5381a2e30b9b9d03ecbd2

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9cab6dd24cdeab69ac13e2a2559eac074af800c9eab71e6ee34d23d9596b42c2
MD5 31ae18c80e407639a894071738a5e9ca
BLAKE2b-256 6800264191fe172170aa1a70777aebfba24bc7c3aa764222ab38ad4555bd15d6

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 1c497d65cba4d1a34afacd84a134325beffcd422190eb2f508001578f7ca5945
MD5 49d83b07d8609d9ebae88fac7ac1be2a
BLAKE2b-256 01458c158965111617ad3b02da12c0f2f0fd05e976a70ed5fd857cce1a8b0c5a

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-cp36-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-cp36-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8c660bd64011eca32a796a77dc52a80ad17d246f1a413ac4a8763643be2fdf69
MD5 9a3d9a82581d5f784bcdbb4df3cdfb17
BLAKE2b-256 0d5bf7177dfd6c65957f34e345b94113a9a5ac30c389352d3ab405d23705587d

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.1-cp36-abi3-macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.1-cp36-abi3-macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 30efce7c20c4e3d243202412ef732109c427aad0b1502adf330ec38f48783c68
MD5 f6e344c6d43616432d4dbb88d9dd7bf2
BLAKE2b-256 83a4948ba60b4bedb9060dd264e3354c34929178b1352bca387e64eb8627c3d7

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