python 解密unionid失败?
按照官方提供的python解密小程序unionid demo 报错 'utf-8' codec can't decode byte 0xba in position 1 :invalid start byte 尝试了将解密结果decode ,同样报错 尝试了各种编码方式,gbk,iso等都报错
def decrypt(self, encryptedData, iv):
try:
sessionKey = base64.b64decode(self.sessionKey)
encryptedData = base64.b64decode(encryptedData)
iv = base64.b64decode(iv)
cipher = AES.new(sessionKey, AES.MODE_CBC, iv)
decrypted = json.loads(self._unpad(cipher.decrypt(encryptedData)))
if decrypted['watermark']['appid'] != self.appId:
raise Exception('Invalid Buffer')
return decrypted
except Exception as err:
print(str(err))
def _unpad(self, s):
return s[:-ord(s[len(s)-1:])]