0

I have to implement the following scenario for the needs of my project.

  1. I am retrieving a dict from a function (whose elements are not serializable)
  2. I want to convert the above mentioned dict into bytes (so I can send it back as a response to the client)
  3. Next, I want these bytes received by the client (in step 2) to be sent again through my web service, and convert again to its initial format (dict).

I tried to follow the example from here by using json.dumps as follows:

cipher_text = hyb_abe.encrypt(master_public_key, fileInBase64Format, policy) #this function comes from the charm-crypto framework and returns a dictionary
encrypted_bytes = json.dumps(cipher_text) # produces error TypeError: Object of type 'Element' is not JSON serializable

The code of hyb_abe.encrypt function is here

but I am getting

TypeError: Object of type 'Element' is not JSON serializable

What could be a workaround for my case?

EDIT

Photo of the value of the dictionary in debug mode

enter image description here

NickAth
  • 1,089
  • 1
  • 14
  • 35
  • [Minimal, complete, verifiable example](http://stackoverflow.com/help/mcve) applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. – Prune Jan 08 '19 at 18:07
  • Hi @Prune , thanks for your interest :) . I think everything was pretty clear but I updated my answer as you can see – NickAth Jan 08 '19 at 18:21
  • Hi @NickAth, what Prune was inferring was that we need to see a chunk of the information you are trying to dump to json. Thanks for showing us the function you are using. That's great! But at a minimum, we also need to see an example of the data so that we know how it could be causing the error (e.g. cannot serialize). – Daniel Scott Jan 08 '19 at 18:39
  • @NickAth JSON has the advantage of being really fast when dumping, but can be picky if its not dealing with string data or straightforward structures. How would you feel about using pickle instead? – Daniel Scott Jan 08 '19 at 18:42
  • Hi @DanielScott yes I have tried with pickle as follows data = pickle.dumps(cipher_text) but I am getting TypeError: can't pickle pairing.Element objects. Unfortunately the content of the dictionary was too big to paste it in a pastebin so I attach a photo of the debugger – NickAth Jan 08 '19 at 19:02
  • I can't find where the photo of the debugger is. – Daniel Scott Jan 08 '19 at 19:04
  • @DanielScott I have attached it :) – NickAth Jan 08 '19 at 19:07
  • 1
    Could you pastebin the contents of element 'C'? From your screenshot, we can see the 2 elements that could be causing the problem. – Daniel Scott Jan 08 '19 at 19:20
  • 1
    Look's like your solution is here: https://stackoverflow.com/questions/43251642/how-to-serialize-store-the-ciphertext-encrypted-by-hybrid-cpabe-bsw07-in-charm – Daniel Scott Jan 08 '19 at 19:23
  • @DanielScott Omg I would not expect to find the same question on SO ! Many thanks – NickAth Jan 08 '19 at 19:39
  • Glad that helps! – Daniel Scott Jan 08 '19 at 19:40

0 Answers0