5

I have a server and client setup where when the client connects, it sends over a JSON object with a username and a public_key.

My current code:

private_key = PrivateKey.generate()
public_key = private_key.public_key
payload = json.dumps({"username": username, "public_key": public_key}).encode('hex')

But I get:

TypeError: <nacl.public.PublicKey object at 0x7fc6ecff18d0> is not JSON serializable

Any solutions?

Awn
  • 817
  • 1
  • 16
  • 33

1 Answers1

6

This is probably a bit late but it's explained here

If you want it as Base64 for example you do

from nacl.encoding import Base64Encoder
print(public_key.encode(Base64Encoder).decode())
jfs
  • 399,953
  • 195
  • 994
  • 1,670
Jan
  • 205
  • 3
  • 9