Git Product home page Git Product logo

fastgm's People

Contributors

123seven avatar wptoux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fastgm's Issues

SM4解密提示密文长度需要是16的整数

看了下源码,有这么一段

   def _bytes_array_to_string(self, buf, mode):
        if mode == 'decrypt':
            if self.padding == 'pkcs7':
                pad_len = buf[-1]
                if PY2:
                    return buf[:-pad_len].tostring()
                else:
                    return buf[:-pad_len].tobytes()
        if PY2:
            return buf.tostring().rstrip(b'\0')
        return buf.tobytes().rstrip(b'\0')

"rstrip(b'\0')",加密返回的结果把末尾的b'\0'截掉,导致解密的的时候长度不对而报错。

sm4 ecb结果错误

gmssl与本库结果不一样

~/Documents via 🐍 v2.7.18 took 2s
❯ ./venv/bin/python                                                                                                                                                                                        15:31:03
Python 3.8.2 (default, Apr  8 2021, 23:19:18)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from gmssl.sm4 import CryptSM4, SM4_ENCRYPT, SM4_DECRYPT
>>> key = b'1'*16
>>> value = b'plain_text'
>>> crypt_sm4.set_key(key, SM4_ENCRYPT)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'crypt_sm4' is not defined
>>> crypt_sm4 = CryptSM4()
>>> crypt_sm4.set_key(key, SM4_ENCRYPT)
>>> encrypt_value = crypt_sm4.crypt_ecb(value)
>>> encrypt_value
b'\x82x=\x13\xb4\x860\xce\x16x\xe9x\xfa\xd0E_'
>>> crypt_sm4.crypt_ecb(value)
b'\x82x=\x13\xb4\x860\xce\x16x\xe9x\xfa\xd0E_'
>>> crypt_sm4.crypt_ecb(value)
b'\x82x=\x13\xb4\x860\xce\x16x\xe9x\xfa\xd0E_'
>>> crypt_sm4.crypt_ecb(value)
b'\x82x=\x13\xb4\x860\xce\x16x\xe9x\xfa\xd0E_'
>>> from base64 import b64encode
>>> b64encode(b'\x82x=\x13\xb4\x860\xce\x16x\xe9x\xfa\xd0E_')
b'gng9E7SGMM4WeOl4+tBFXw=='
~/Documents via 🐍 v2.7.18 took 14s
❯ ./venv/bin/python                                                                                                                                                                                        15:24:31
Python 3.8.2 (default, Apr  8 2021, 23:19:18)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from fastgm import SM4
>>> SM4(b'1'*16).encrypt_ecb(b'plain_text')
b'Bws\x98\x1f\xfd|\xfcL\xc7J\xca\xa5;\t\xa3'
>>> from base64 import b64encode
>>> b64encode(b'Bws\x98\x1f\xfd|\xfcL\xc7J\xca\xa5;\t\xa3')
b'QndzmB/9fPxMx0rKpTsJow=='

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.