Skip to main content

Tongsuo Python SDK

Project description

tongsuo-python-sdk

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

SM2签名,详见sm2_sign.py

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

key = ec.EllipticCurvePrivateNumbers(
    int(d, 16),
    ec.EllipticCurvePublicNumbers(int(Qx, 16), int(Qy, 16), ec.SM2()),
).private_key()
signature = key.sign(msg, ec.ECDSA(hashes.SM3()))

SM2验签,详见sm2_verify.py

from tongsuopy.crypto import hashes
from tongsuopy.crypto.asymciphers import ec
from tongsuopy.crypto.asymciphers.utils import encode_dss_signature

signature = encode_dss_signature(R, S)

pubkey = ec.EllipticCurvePublicNumbers(
    (Qx, Qy), ec.SM2()
).public_key()
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.0-pp39-pypy39_pp73-win_amd64.whl (1.3 MB view details)

Uploaded PyPyWindows x86-64

tongsuopy-1.0.0-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.0-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.0-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.0-pp39-pypy39_pp73-macosx_10_12_x86_64.whl (1.5 MB view details)

Uploaded PyPymacOS 10.12+ x86-64

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

Uploaded PyPyWindows x86-64

tongsuopy-1.0.0-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.0-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.0-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.0-pp38-pypy38_pp73-macosx_10_12_x86_64.whl (1.5 MB view details)

Uploaded PyPymacOS 10.12+ x86-64

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

Uploaded CPython 3.6+Windows x86-64

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

Uploaded CPython 3.6+Windows x86

tongsuopy-1.0.0-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.0-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.0-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.0-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.0-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.0-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.0-pp39-pypy39_pp73-win_amd64.whl.

File metadata

File hashes

Hashes for tongsuopy-1.0.0-pp39-pypy39_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 ca783562d498cf17af8d35d3e4d5c6fd9c500c57985eaad0c807cd1ea40909b8
MD5 966df5a8474bb19624b48d784e077bc2
BLAKE2b-256 4fb8b6c7b213e7884dbce665ada7b920ecc92af5ff9b53cdd69d3e527b5ba968

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-pp39-pypy39_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3cb3fa01c581caa2ce0c6485fca18d45fb6788c5ff450cb6eede536a1d1a53b3
MD5 6e55c8b676372ba8b353a04656c76107
BLAKE2b-256 f2efefdc72ebd58d44b6b0c46f9b15848476ee40462f22e799e118c075c6492a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8b3765c2ed6256e9a285823eacecdbcf0f8bf4e537b5b41f5611a969ad8929b1
MD5 d792db82f529f58b94c21aec069c66bf
BLAKE2b-256 4963a55a6353ebb917d7f18bd46ba8db8fffbe93be401f3da963c288f6d3619a

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.0-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.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 d09d5f78f75d73d8b34e793ff159f1d0b8c6ddd7d2fec74dac7474428609a4d2
MD5 f64718fd0ac03d95fe2b6f1687db93dc
BLAKE2b-256 fc939bf26a3211ee61a983d7b73fd406b39b32c357202bbbfd877bc72a57d7d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-pp39-pypy39_pp73-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 79314df22ba00f2de0dcb9b30357e9300a4c82cfdb79639dd7609ff5d047c70c
MD5 efc947a74c75645eeec07835ec4beddd
BLAKE2b-256 0444269de07d1b48632383f4d4134f47aeaee08fcf963f8c742abba18d3f95e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-pp38-pypy38_pp73-win_amd64.whl
Algorithm Hash digest
SHA256 d32dffb67773f697accbdf9e7b1ba207fe5defbe9941ef9904c5aa631d8e6f96
MD5 e4b59b046639a99276616c37b0764641
BLAKE2b-256 6264a02fda4fda908884048bd830f4d21d867cc772480fa47c347a88991ef9f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-pp38-pypy38_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d9e85e1395a3764e9dcf0d5cb7b8da87fcef94a49cd9e674c5b4d750aebd53d6
MD5 1db9e2b79f632480e27881eb6bb40973
BLAKE2b-256 d92900312b23b871fbec537c07558addbb9f114d13779cd99d44b71ce2e7e8f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34baf91a6271d29e012e496eb8c0d78ea140f1f5a43ab7eefed33c062a031a5a
MD5 006317495f89238c324dae3cbff12123
BLAKE2b-256 058062fc1591f9e706a4a52000fc1b39a0c35e99a78b6e7f28fd9433d223cf40

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.0-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.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 b1810d99a99bf5cab8857a99170d361ef50e45d1bcf7d8b9f1fc496286d0ee87
MD5 5d01d4941a1d283be491091e750eb013
BLAKE2b-256 7cf574cf4809d0828f0f72cc2b5018cf107513e72235c45f6346e61a369cf836

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-pp38-pypy38_pp73-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e2029a052eea425e43f0ee3cc7c55d515af1e77fb80c12b15128b332c7e8f3f9
MD5 453a709bcaf734839242f8ff3d394763
BLAKE2b-256 5b2ca48f8511a449dec8b4e6a34269a3b1de3ed08fca7c6574959302c2da66d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tongsuopy-1.0.0-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.0-cp36-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 30ec389cd8a4f72343ac08648fc4a5739fcfa893263b9b7daf8fa21b1a6697e5
MD5 336c814c3a9c844ed86b6b88a23a7585
BLAKE2b-256 21f660965e2bcd01e461b9641024f44e8e2099ebdf558429939a0aa3d512a0ad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tongsuopy-1.0.0-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.0-cp36-abi3-win32.whl
Algorithm Hash digest
SHA256 0af21a8f25aa2c69125333977f177e1a6e33f9fc106827202b196034d1dd2b3e
MD5 e5bf061af1c969761ae363c623b612bb
BLAKE2b-256 2b384ed89b6bd8ee06319ac210d0520ca6500bffd14d7f83b89ac50d10762e60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 68b06a200fdb43b4bd0e17d92c6a5ec46a455aa89752afd8b088beeb9814adf8
MD5 c8479bf01f244bc194f969012391e763
BLAKE2b-256 f2f6f57d831c3a5781d8828e36b231bafe9032fc8ac1161f4036020c91d640fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-cp36-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1fb222eb14ad1ce98f0d2210402516e1a8050666d0daf43655a7660d9a3bef5e
MD5 79b733ea3b55e08fffe278c1b4e6a746
BLAKE2b-256 80d95654eb8d6c7627445ff12dabc5357a82f2466181325be058aa8a41d2df71

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ecf6176866cbc4236d8dfcba48772777c38918e4219c6266a074819da976e090
MD5 a072db8816772340268afb7fc786f8a6
BLAKE2b-256 6dde6f04c386b75a2b5bba1d6a7695963773ed6a22ff2396995751b93a181cbe

See more details on using hashes here.

File details

Details for the file tongsuopy-1.0.0-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.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 b4d98277b8b41617f46648d282cd7af61f2a293949320b49d5c64b09c903f001
MD5 6130c8a0fa74ac54fc96b45435b9ef53
BLAKE2b-256 4fab45005a624a79b51b77f296a7e87ca82e3be346d007e3473054cb268f39b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-cp36-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 27729d0a27f2f1e0e64fd9ec59270f5e5bc56ec9814c25f7f6752810a47f9e2d
MD5 3abb09d7eb4a32425dfb7e75488d9097
BLAKE2b-256 ab5dd603a8e13fdd33ee5795bbddc5108b99bfbb06fad935095fe6ab1fd51bcd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tongsuopy-1.0.0-cp36-abi3-macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 bce974112535fdf498b2965ce961f6bf23edcc19a52ca7579e55d7f4f95b90d3
MD5 02b03d4ba2be9f2f5c2f39fef211180c
BLAKE2b-256 d42c89aa2dc4db09348cad884688defa2c0017aa36dd4310c800aacd06978762

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