在Charm-Crypto中序列化和反序列化组元素 [英] Serializing and deserializing group elements in Charm-Crypto

查看:1364
本文介绍了在Charm-Crypto中序列化和反序列化组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助将椭圆曲线配对组元素的列表表示(字符串)转换回对象。

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

说明:

I我使用charm crypto v0.43在我的Web应用程序中使用CPABE方案。我需要将生成的配对元素存储到我的数据库中。当我这样做,它是将其存储为列表。我需要将其映射回配对组元素对象。

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.

转换:

[771281202364725359015275543519860265278248937600027018972741977722880288402810467924555583431036045929994018001453439703799448692568829067937466068366897, 5928426678871551838449004494119368314093842432141364739971117261348155912543962117516776973405646414105108743246860323245910977796691638669773215755592297]

<pairing.Element object at 0x7f1a1e840300>`

代码:

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


推荐答案

对我的问题。这是我做的。

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

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

您可以使用groups serialize函数序列化 g / p>

You can serialize g using groups serialize function:

str = group.serialze(g)

您可以使用

obj = group.deserialize(str)

希望它可以帮助面对同一问题的人。

Hope it might help somebody facing the same issue.

这篇关于在Charm-Crypto中序列化和反序列化组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆