示例#1
0
    def decode(data):#data byte[]
        des = DES('12345678','1234567812345678')
        encryptdata = None
        if type(data) != type(''):
            data = data.decode('utf-8')

        print("data:"+data)
        # data = data.encode('utf-8')
        try:
            encryptdata = des.decrypt(data)
        except:
            print('exception !!!!!!!!!!!!!!')
        sde_data = encryptdata.decode('utf-8')#to string
        #log here sde_data
        print(sde_data)
        # logging.info("receive data"+ sde_data)
        try:
            MessageTools.log.info("receive data"+ sde_data)
        except BaseException as e :
            pass
        receiveDic = MyDecoder().decode(sde_data)
        return receiveDic
示例#2
0
    def encode(object,isencrypt = True):
        jsonStr = MyEncoder().encode(object)
        #log here jsonStr
        print(jsonStr)
        # logging.info("respond data"+ jsonStr)
        try:
            MessageTools.log.info("respond data"+ jsonStr)
        except BaseException as e :
            pass
        if isencrypt:
            timeBefore = GameTools.getDatetimeNow()
            bjson = jsonStr.encode(encoding= "utf8")
            des = DES('12345678','1234567812345678')
            encryptdata = des.encrypt(bjson)

            sss = encryptdata.decode('utf-8')
            timeAfter = GameTools.getDatetimeNow()
            alpha = timeAfter - timeBefore
            print('total seconds :%s' %alpha.total_seconds())
            sss = "1111%s"%jsonStr
        else:
            sss = "0000%s"%jsonStr
        return sss
示例#3
0
def des_encode():
    data = '{"udid":"a1fdadceef38c9c2040a2199b1d41e67","token":null}'
    des = DES('12345678','1234567812345678')
    encryptdata = des.encrypt(data.encode('utf-8'))
    print(encryptdata)