I am using jwcrypto
to encrypt data using public key. I have gone through the documentation and the JWE
class only takes plaintext as payload.
But I have a dictionary to encrypt as a payload.
I can convert the dictionary to json and encrypt the payload but the one who decrypt my data will be expecting dictionary after decription.
Is there anyway I can encrypt dictionary as payload.
JWE defines a JSON-friendly way to encrypt arbitrary data.
So what you want (encrypt a python dictionary, which maps to a JSON object) is not a JWE but actually a JWT token. A JWT is basically using the JWS and JWE standards to sign and/or encrypt a JSON object.
Just use the JWT part of jwcrypto doc: https://jwcrypto.readthedocs.io/en/latest/jwt.html
Should be something like that:
Then the deserialization must be done with a library assuming that the token is a JWT otherwise you indeed end up with a string representation of the JSON payload, that you will have to decode yourself to a Python dict.