0

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

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

PairingGroup 具有编码/解码方法,但未实现。我只想用“Hello world!”试试这个。

4

1 回答 1

1

查看charm/charm/test/toolbox/symcrypto_test.py下的这个类

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)
于 2016-07-11T13:55:00.800 回答