JHUISI/charm

loading keys after saving in files

MahmoudAbouyoussef opened this issue · 1 comments

I am working on Charm-crypto library on group signature. I generated the keys (gpk, and gsk[user]), and saved the private key in a txt file. when i tried to load the keys from the text file to sign a message, it give me an error saying invalid types.

T3 = A * (gpk['h'] ** (alpha + beta)) Error: invalid types.

A is the first element of the gsk[user] = (A, X)

the type of A if i directly used the generated key before saving it in the text file is pairing.Element () (The signature succeeds here without any errors)

the type of A after loading from the text file is list () and this gives the error.

can anyone help in clarifying how to make the loaded keys has the same data types as the generated keys before loading.

Thanks in advance

Depending on the used schemes and the underlying curves there are suitable mechanisms for this. I have picked out an example for PairingGroups:

https://jhuisi.github.io/charm/toolbox/pairinggroup.html?highlight=pairinggroup#pairinggroup.PairingGroup.serialize

Here you can use the function 'serialize' to convert an object into bytes and 'deserialize' to convert bytes back into an element of the group. As you can see in the example, both functions are assigned to the respective group.

In general you might also want to have a look at the serialization API:
https://jhuisi.github.io/charm/developers.html#using-serialization-api