How to serialize the ciphertext encrypted by CPabe.py in charm crypto

69 views
Skip to first unread message

Jihane JEBRANE

unread,
Sep 5, 2022, 6:05:25 PM9/5/22
to Charm-Crypto Help
Hi, 
I want to serialize the ciphertext encrypted by CPabe.py using objectToBytes() but when I want to deserialize it by bytesToObject() and compute the cpabe.decrypt I found this error. 

" Invalid type: 1 not <type unicode > ".
Can someone help me solve this, please?
Thanks in advance,
Jihane.

Edoardo Marangone

unread,
Sep 6, 2022, 3:18:51 AM9/6/22
to charm-...@googlegroups.com
Hi,

Do you have this problem with charm-crypto or with cake architecture?

Usually when the deserialization doesn't work there is a problem with some special unsupported characters. Please let me know which architecture you are using and I'll try to fix the problem.

Thank you,
Edoardo


--
You received this message because you are subscribed to the Google Groups "Charm-Crypto Help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to charm-crypto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/charm-crypto/b8f4e0ec-e0ba-41b7-b442-e3c4de7c016bn%40googlegroups.com.

Fai crescere le giovani ricercatrici e i giovani ricercatori
con il 5 per mille alla Sapienza
Scrivi il codice fiscale dell'Università 80209930587
Cinque per mille

Jihane JEBRANE

unread,
Sep 6, 2022, 12:33:12 PM9/6/22
to charm-...@googlegroups.com
Hi,
Thank you very much for the prompt reply. 
So basically, I'm trying to implement an auth protocol based on the CPabe scheme using a web socket in charm-crypto. 
This is a part of my code : 

def Server_state1(self, input):
group = PairingGroup('SS512')
cpabe = CPabe_BSW07(group)
msg group random(GT)
attributes = ['ONE', 'TWO', 'THREE']
access_policy = ' ((four or three_ and (three or one)) '
(master_public_key, master_key ) = cpabe.setup()
secret_key = cpabe.keygen(master_public_key,master_key, attributes)
cipher_text = cpabe.encrypt(master_public, msg, access_policy)               #  type (cipher_text) = dict
Ciph = objectToBytes(cipher_text, group)
p_k= objectToBytes( master_public_key  , group)
S_k= objectToBytes( secret_key , group)   
return {'cipher': Ciph, 'pk' : p_k, 'sk' : S_k}
def User_state3(self,input):
ciph_rec = input.get('cipher')
pk_rec = input.get('pk')
sk_rec = input.get('sk')
cipher_text = bytesToObject(ciph_rec, group)
public_key = bytesToObject(pk_rec, group)
Secret_key = bytesToObject(sk_rec, group)
decrypt_text = cpabe.decrypt(public_key, Secret_key, cipher_text)
print(decrypt_text)

### result
 " Invalid type: 1 not <type unicode > " 

I hope it's clear...

Thanks in advance,
Jihane.


Edoardo Marangone

unread,
Sep 7, 2022, 4:27:03 AM9/7/22
to charm-...@googlegroups.com
Maybe I've understood your problem. You can't serialize with an objectToBytes function the ciphertext. You have to do some work in order to obtain a serialization (and then a de-serialization). Check my code in CAKE in the 'ecoders_decoders.py' script. There you will find all the necessary passages to do to serialize (and deserialize) the ciphertext in a proper way.

I hope you can manage it.

Thanks,
Edoardo

Jihane JEBRANE

unread,
Sep 7, 2022, 1:51:30 PM9/7/22
to charm-...@googlegroups.com
Hi, 
Thank you very much. I finally found out how to solve it using this link. I appreciate your help, sir.


Best regards,
Jihane JEBRANE.

Edoardo Marangone

unread,
Sep 8, 2022, 2:37:32 AM9/8/22
to charm-...@googlegroups.com
Ok great, if you have any problems don’t hesitate to write me. 

Best regards,
Edoardo 

From: charm-...@googlegroups.com <charm-...@googlegroups.com> on behalf of Jihane JEBRANE <jihan...@gmail.com>
Sent: Wednesday, September 7, 2022 7:51:14 PM
To: charm-...@googlegroups.com <charm-...@googlegroups.com>
Subject: Re: How to serialize the ciphertext encrypted by CPabe.py in charm crypto
 
Reply all
Reply to author
Forward
0 new messages