I'm realy a newbie in cryptography, I want to do MQTT payload encryption with AES, i've done it with PyCrypto library, but i'm still wondering how I can encrypt AES key before sending it to the subscriber, so i choose Python library called PyNacl to do that with ECC (curve25519), but i have no idea how to exchange the public key between the publisher and subscriber, have you any idea to do that ?

1 Answer 1


Public keys by definition are public (no need to keep them secret).

So there is no reason it can't be available for download via http or at a push published as a retained message on a known MQTT topic.

  • thanks for responding if i got what you said , i can exchange public key in a separate topic and play with the code so that the message is sent only after receipt of the public key , right? Commented Aug 6, 2018 at 15:43
  • As a retained message the key would be delivered to the device as soon as it subscribed to the topic
    – hardillb
    Commented Aug 6, 2018 at 15:44
  • please I am stuck in python code, here is the scenario, client A want to send encrypted data to client B, but first he must receive client B public key, so both client A and B are publisher and subscriber at the same time on the same topic, client B send his public key as a retained message then B encrypt data and send it to B, for me it seems confusing when i want to implement it in paho mqtt python , have you any example to do that ? Commented Aug 7, 2018 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.