fastgm
fastgm copied to clipboard
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'截掉,导致解密的的时候长度不对而报错。