Giter Site home page Giter Site logo

snowland-smx-python's Introduction

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)

snowland-smx-python's People

Contributors

astarchen avatar fossabot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.