据我所知,实现的 Charm 方案仅允许您加密随机生成的组元素或编码为组元素的 msg 字符串。但是这些也有局限性,因为群元素的顺序是从素数推导出来的。
有没有办法扩展魅力方案来加密文件?
根据 Artjom B 的评论编辑:
def encrypt(self, pk, M, object):
key = self.group.random(GT)
c1 = abenc.encrypt(pk, key, object)
# instantiate a symmetric enc scheme from this key
cipher = AuthenticatedCryptoAbstraction(sha1(key))
c2 = cipher.encrypt(M)
return { 'c1':c1, 'c2':c2 }
f = open(pth,'r')
message = f.read()
pk, mk = abenc.setup()
att_list=['TWO','FOUR']
access_policy = '((four or three) and (two or one))'
sk = abenc.keygen(pk, mk, att_list)
ct = encrypt(pk, message, access_policy)