优化工单模块,增加企微模块
This commit is contained in:
23
sg_wechat_enterprise/we_api/crypto/pkcs7.py
Normal file
23
sg_wechat_enterprise/we_api/crypto/pkcs7.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from wechatpy.utils import to_binary, byte2int
|
||||
|
||||
|
||||
class PKCS7Encoder(object):
|
||||
block_size = 32
|
||||
|
||||
@classmethod
|
||||
def encode(cls, text):
|
||||
length = len(text)
|
||||
padding_count = cls.block_size - length % cls.block_size
|
||||
if padding_count == 0:
|
||||
padding_count = cls.block_size
|
||||
padding = to_binary(chr(padding_count))
|
||||
return text + padding * padding_count
|
||||
|
||||
@classmethod
|
||||
def decode(cls, decrypted):
|
||||
padding = byte2int(decrypted[-1])
|
||||
if padding < 1 or padding > 32:
|
||||
padding = 0
|
||||
return decrypted[:-padding]
|
||||
Reference in New Issue
Block a user