Serializing and deserializing group elements in Charm-Crypto

浪子不回头ぞ 提交于 2019-12-13 12:34:19

问题


I need help to convert the list representation (string) of elliptic curve pairing group element back to an object.

Explanation:
I am using charm crypto v0.43 to use CPABE scheme in my web application. I need to store the pairing element that is generated into my database. When I did that, it is storing it as list. I need to map it back to pairing group element object.

Convert:

[771281202364725359015275543519860265278248937600027018972741977722880288402810467924555583431036045929994018001453439703799448692568829067937466068366897, 5928426678871551838449004494119368314093842432141364739971117261348155912543962117516776973405646414105108743246860323245910977796691638669773215755592297]

to

<pairing.Element object at 0x7f1a1e840300>`

Code:

group = PairingGroup('SS512')
alpha = group.random(ZR)
g= group.random(G1)

回答1:


Found a solution to my problem. Here is what i did.

g = group.random(G1) # generates a random group element in that pairing group

You can serialize g using groups serialize function:

str = group.serialze(g)

You can deserialize it using

obj = group.deserialize(str)

Hope it might help somebody facing the same issue.



来源:https://stackoverflow.com/questions/34446758/serializing-and-deserializing-group-elements-in-charm-crypto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!