【问题标题】:How to encode data for use in Charm's attribute based encryption?如何对数据进行编码以用于 Charm 基于属性的加密?
【发布时间】:2016-07-07 18:43:34
【问题描述】:

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

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

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

【问题讨论】:

    标签: python cryptography charm-crypto


    【解决方案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)
    

    【讨论】:

    • 谢谢!另外,我在 charm/charm/adapters/ 中发现 abenc_adapt_hybrid.py 有类似的代码。
    猜你喜欢
    • 1970-01-01
    • 2017-01-28
    • 2018-05-16
    • 1970-01-01
    • 1970-01-01
    • 2015-10-29
    • 1970-01-01
    • 1970-01-01
    • 2017-05-14
    相关资源
    最近更新 更多