1 Star 0 Fork 28

阳甯/snowland-smx-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
README.en.rst 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
A.Star 提交于 2019-05-17 13:04 . 提交文档

snowland-smx-python

  1. SM2
    gm signature a. generate keypair
>>> from pysmx.SM2 import generate_keypair
>>> pk, sk = generate_keypair()
  1. signature
>>> from pysmx.SM2 import Sign
>>> len_para = 64
>>> sig = Sign("hello", sk, '12345678abcdef', len_para)
  1. verify
>>> from pysmx.SM2 import Verify
>>> len_para = 64
>>> Verify(sig, "hello", pk, len_para)
  1. encrpto
>>> from pysmx.SM2 import Encrypt
>>> e = b'hello'
>>> len_para = 64
>>> C = Encrypt(e, pk, len_para, 0)  # 0 means var e is not a hex string
  1. decrpto
>>> from  pysmx.SM2 import Decrypt
>>> len_para = 64
>>> m = Decrypt(C, sk, len_para)
  1. SM3
    hash a. method 1:
>>> from pysmx.SM3 import SM3
>>> sm3 = SM3()
>>> sm3.update('abc')
>>> sm3.hexdigest()
  1. method 2:
>>> from pysmx.SM3 import hash_msg
>>> s = 'abc'
>>> hash_msg(s)
  1. SM4
    block encrpto a. encrpto
>>> from pysmx.SM4 import Sm4, ENCRYPT, DECRYPT
>>> key_data = b'hello word errrr...'  # 16 bytes at least
>>> sm4 = Sm4()
>>> input_data = [1,2,3]
>>> sm4.sm4_set_key(key_data, ENCRYPT)
>>> msg = sm4.sm4_crypt_ecb()
  1. decryto
>>> from pysmx.SM4 import Sm4, ENCRYPT, DECRYPT
>>> key_data = b'hello word errrr...'  # 16 bytes at least
>>> sm4 = Sm4()
>>> sm4.sm4_set_key(key_data, DECRYPT)
>>> sm4.sm4_crypt_ecb(msg)
  1. ZUC
    waiting for update
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/RooTwo/snowland-smx-python.git
[email protected]:RooTwo/snowland-smx-python.git
RooTwo
snowland-smx-python
snowland-smx-python
master

搜索帮助