def encrypt(self,text,corpid):
"""???????
@param text: ???????
@return: ????????
"""
# 16?????????????
text = self.get_random_str() + struct.pack("I",socket.htonl(len(text))) + text + corpid
# ???????????????????
pkcs7 = PKCS7Encoder()
text = pkcs7.encode(text)
# ??
cryptor = AES.new(self.key,self.mode,self.key[:16])
try:
ciphertext = cryptor.encrypt(text)
# ??BASE64????????????
return ierror.WXBizMsgCrypt_OK, base64.b64encode(ciphertext)
except Exception,e:
print e
return ierror.WXBizMsgCrypt_EncryptAES_Error,None
评论列表
文章目录