使用AES解码时,如何在没有其他更改的情况下获得正确的消息?

时间:2019-03-26 02:27:29

标签: python encryption aes

我正在尝试使用通过pyaes的AES加密进行MQTT应用程序。在解码期间,我使用b'Message'而不是消息来获取输入。如何确保消息只是打印出来?修剪和过渡功能不起作用

import time
import paho.mqtt.client as mqtt
import os
import pyaes
import sys

# This is the Subscriber

def on_connect(client, userdata, flags, rc):
  print("Connected with result code "+str(rc))
  client.subscribe("topic/test")

def on_message(client, userdata, msg):
    #keys = os.urandom(16)
    #iv   = os.urandom(16)

    keys = //Random Keys
    iv   = //Random IV Key
    bart = pyaes.AESModeOfOperationOFB(keys,iv=iv)

    decrypted = bart.decrypt(msg.payload)
    #print(msg.payload,"\n")
    print("Message is : ",decrypted,"\n")
    client.disconnect()

broker      = "192.168.1.104"
port        = 1883
keepalive   = 60

client = mqtt.Client()
client.connect(broker,port,keepalive)

client.on_connect = on_connect
client.on_message = on_message

client.loop_forever()

输出消息输出:b'这是消息'

我希望输出输出:这是消息

0 个答案:

没有答案