I'm using Charm Crypto from Github. I'd like to use the attribute based encryption algorithms. The test code works fine, however, it uses a random message generated from PairingGroup. How do I use my own data for encryption?
>>> group = PairingGroup('SS512', secparam=512)
>>> msg = group.random(GT)
The PairingGroup has encode/decode methods, but they are not implemented. I just want to try this with "Hello world!".
Look at this class under 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)
from charm.toolbox.pairinggroup import PairingGroup, GT
from ac17 import AC17CPABE
def main():
# instantiate a bilinear pairing map
pairing_group = PairingGroup('MNT224')
# AC17 CP-ABE under DLIN (2-linear)
cpabe = AC17CPABE(pairing_group, 2)
# run the set up
(pk, msk) = cpabe.setup()
# generate a key
attr_list = ['ONE', 'TWO', 'THREE']
key = cpabe.keygen(pk, msk, attr_list)
# choose a random message
msg = pairing_group.random(GT)
# generate a ciphertext
policy_str = '((ONE and THREE) and (TWO OR FOUR))'
ctxt = cpabe.encrypt(pk, msg, policy_str)
# decryption
rec_msg = cpabe.decrypt(pk, ctxt, key)
if debug:
if rec_msg == msg:
print ("Successful decryption.")
else:
print ("Decryption failed.")
if __name__ == "__main__":
debug = False
main()
I want to encrypt "hello world" too, how can I convert the msg
whose type is str or bytes to pairing.Element?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.