如何编码数据以用于 Charm 的基于属性的加密?

How to encode data for use in Charm's attribute based encryption?

我正在使用 Github 的 Charm Crypto。我想使用基于属性的加密算法。测试代码工作正常,但是,它使用从 PairingGroup 生成的随机消息。如何使用自己的数据进行加密?

>>> group = PairingGroup('SS512', secparam=512)
>>> msg = group.random(GT)

PairingGroup 有 encode/decode 个方法,但没有实现。我只想用 "Hello world!" 试试这个。

在charm/charm/test/toolbox/symcrypto_test.py

下看这个class
class SymmetricCryptoAbstractionTest(unittest.TestCase):

def testAESCBC(self):
    self.MsgtestAESCBC(b"hello world")

def testAESCBCLong(self):
    self.MsgtestAESCBC(b"Lots of people working in cryptography have no deep \
   concern with real application issues. They are trying to discover things \
    clever enough to write papers about -- Whitfield Diffie.")

def testAESCBC_Seperate(self):
    self.MsgTestAESCBCSeperate(b"Lots of people working in cryptography have no deep \
    concern with real application issues. They are trying to discover things \
    clever enough to write papers about -- Whitfield Diffie.")

def MsgtestAESCBC(self,msg):
    groupObj = PairingGroup('SS512')
    a =  SymmetricCryptoAbstraction(sha1(groupObj.random(GT)))
    ct = a.encrypt(msg)
    dmsg = a.decrypt(ct);
    assert msg == dmsg , 'o: =>%s\nm: =>%s' % (msg, dmsg)

def MsgTestAESCBCSeperate(self,msg):
    groupObj = PairingGroup('SS512')
    ran = groupObj.random(GT)
    a =  SymmetricCryptoAbstraction(sha1(ran))
    ct = a.encrypt(msg)        
    b =  SymmetricCryptoAbstraction(sha1(ran))
    dmsg = b.decrypt(ct);
    assert msg == dmsg , 'o: =>%s\nm: =>%s' % (msg, dmsg)