/snowland-smx-python

Primary LanguagePythonBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

snowland-smx-python

安装: pip 安装 ** pip install snowland-smx **

或者

源码安装 ** python setup.py install **

  1. SM2

国密公钥加解密签名验签

  1. 密钥生成
>>> from pysmx.SM2 import generate_keypair
>>> pk, sk = generate_keypair()
  1. 签名
>>> from pysmx.SM2 import Sign
>>> len_para = 64
>>> sig = Sign("你好", sk, '12345678abcdef', len_para)
  1. 验签
>>> from pysmx.SM2 import Verify
>>> len_para = 64
>>> Verify(sig, "你好", pk, len_para)
  1. 加密
>>> from pysmx.SM2 import Encrypt
>>> e = b'hello'
>>> len_para = 64
>>> C = Encrypt(e, pk, len_para, 0)  # 此处的1代表e是否是16进制字符串
  1. 解密
>>> from  pysmx.SM2 import Decrypt
>>> len_para = 64
>>> m = Decrypt(C, sk, len_para)

#. SM3 [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FASTARCHEN%2Fsnowland-smx-python.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FASTARCHEN%2Fsnowland-smx-python?ref=badge_shield)

国密哈希 a. 方法1:

>>> from pysmx.SM3 import SM3
>>> sm3 = SM3()
>>> sm3.update('abc')
>>> sm3.hexdigest()
  1. 方法2:
>>> from pysmx.SM3 import hash_msg
>>> s = 'abc'
>>> hash_msg(s)
  1. SM4

国密私钥加解密 a. 加密

>>> from pysmx.SM4 import Sm4, ENCRYPT, DECRYPT
>>> key_data = b'hello word errrr...'  # 至少16字节
>>> sm4 = Sm4()
>>> input_data = [1,2,3]
>>> sm4.sm4_set_key(key_data, ENCRYPT)
>>> msg = sm4.sm4_crypt_ecb()
  1. 解密
>>> from pysmx.SM4 import Sm4, ENCRYPT, DECRYPT
>>> key_data = b'hello word errrr...'  # 至少16字节
>>> sm4 = Sm4()
>>> sm4.sm4_set_key(key_data, DECRYPT)
>>> sm4.sm4_crypt_ecb(msg)
  1. ZUC
waiting for update

## License [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FASTARCHEN%2Fsnowland-smx-python.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FASTARCHEN%2Fsnowland-smx-python?ref=badge_large)