I'm trying to store the private/public keys as UTF-8 strings in a database. The problem is that when I bring them back into code, they are not the correct type. As bytes they print the same, as per the following code:
import nacl.utils
from nacl.public import PrivateKey, SealedBox
from nacl.encoding import Base64Encoder
import base64
prvkbob = PrivateKey.generate()
pubkbob = prvkbob.public_key
prvk_db = prvkbob.encode(Base64Encoder).decode('utf8')
pubk_db = pubkbob.encode(Base64Encoder).decode('utf8')
prvk = base64.b64decode(prvk_db.encode('utf8'))
shdk = base64.b64decode(pubk_db.encode('utf8'))
print(prvkbob)
print(prvk)
print(pubkbob)
print(shdk)
# It works with the original key
sealed_box = SealedBox(prvkbob)
# Error on key returned from database
sealed_box = SealedBox(prvk)
How do I initialize them as PublicKey or PrivateKey objects?