コード例 #1
0
	def decrypt(self, sKey, serializedCiphertext):
		''' Decrypt the provided ciphertext sing the secret key. Decryption is only successful if
		the policy embedded in the secret key matches the ciphertext access policy.

		NOTE: there is a bug in Charm (?) where a policy of a single value causes an error to be thrown: 

		unsupported right operand types: int, bytes, str

		Sample code that throws the error: 
		enc2 = EncryptionModule()
		policy = '(three)' 
		attrs = ['ONE', 'TWO', 'THREE']
		msg = "Hello world!"
		ct2 = enc2.encrypt(msg, policy)
		sk2 = enc2.generateUserKey(attrs) 
		enc2.decrypt(sk2, ct2)

		'''
		ciphertext = bytesToObject(serializedCiphertext, self.groupObj)
		c1, c2 = ciphertext['c1'], ciphertext['c2']
		success = True
		try:
			key = self.cpabe.decrypt(self.public, sKey, c1)
			if (key == False):
				success = False
		except:
			success = False

		# Try to perform the decryption if we were able to recover the key
		plaintext = None
		if (success == True):
			cipher = AuthenticatedCryptoAbstraction(sha1(key))
			plaintext = cipher.decrypt(c2)
		return (success, plaintext)
コード例 #2
0
 def decrypt(self, pk, sk, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = abenc.decrypt(pk, sk, c1)
     print type(key), key
     cipher = AuthenticatedCryptoAbstraction(sha1(key))
     print cipher
     return cipher.decrypt(c2)
コード例 #3
0
def encryptAES(encryptionFileAES):
    keyAES = group.random(GT)
    symcrypt = AuthenticatedCryptoAbstraction(extractor(
        keyAES))  # or SymmetricCryptoAbstraction without authentication
    ciphertext = symcrypt.encrypt(encryptionFileAES)

    return keyAES, ciphertext
コード例 #4
0
 def symEnc(self, message):
     try:
         cipher = AuthenticatedCryptoAbstraction(self.symkey)
         return cipher.encrypt(message)
     except AttributeError:
         print('Please init a symmetric key')
         raise
コード例 #5
0
 def symDec(self, ciphtext):
     try:
         cipher = AuthenticatedCryptoAbstraction(self.symkey)
         return cipher.decrypt(ciphtext)
     except AttributeError:
         print('Please init a symmetric key')
         raise
コード例 #6
0
 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 }
コード例 #7
0
 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}
コード例 #8
0
def hash(msg):
    xi = chamHash.hash(pk, sk, msg)
    etd = [xi['p1'], xi['q1']]
    #if debug: print("Hash...")
    #if debug: print("hash result =>", xi)

    # encrypt
    rand_key = groupObj.random(GT)
    #if debug: print("msg =>", rand_key)
    #encrypt rand_key
    maabect = maabe.encrypt(public_parameters, maabepk, rand_key,
                            access_policy)
    #rand_key->symkey AE
    symcrypt = AuthenticatedCryptoAbstraction(extractor(rand_key))
    #symcrypt msg(etd=(p1,q1))
    etdtostr = [str(i) for i in etd]
    etdsumstr = etdtostr[0] + etdtostr[1]
    symct = symcrypt.encrypt(etdsumstr)

    ct = {'rkc': maabect, 'ec': symct}

    #if debug: print("\n\nCiphertext...\n")
    #groupObj.debug(ct)
    #print("ciphertext:=>", ct)
    h = {
        'h': xi['h'],
        'r': xi['r'],
        'cipher': ct,
        'N1': xi['N1'],
        'e': xi['e']
    }
    return h
コード例 #9
0
 def decrypt(self, pk, sk, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = abenc.decrypt(pk, sk, c1)
     if key is False:
         raise Exception("failed to decrypt!")
     cipher = AuthenticatedCryptoAbstraction(sha2(key))
     return cipher.decrypt(c2)
コード例 #10
0
def collision(msg1, msg2, h):
    #decrypt rand_key
    rec_key = maabe.decrypt(public_parameters, user_sk, h['cipher']['rkc'])
    #rec_key->symkey AE
    rec_symcrypt = AuthenticatedCryptoAbstraction(extractor(rec_key))
    #symdecrypt rec_etdsumstr
    rec_etdsumbytes = rec_symcrypt.decrypt(h['cipher']['ec'])
    rec_etdsumstr = str(rec_etdsumbytes, encoding="utf8")
    #print("etdsumstr type=>",type(rec_etdsumstr))
    #sumstr->etd str list
    rec_etdtolist = cut_text(rec_etdsumstr, 309)
    # print("rec_etdtolist=>",rec_etdtolist)
    #etd str list->etd integer list
    rec_etdint = {
        'p1': integer(int(rec_etdtolist[0])),
        'q1': integer(int(rec_etdtolist[1]))
    }
    #print("rec_etdint=>",rec_etdint)
    r1 = chamHash.collision(msg1, msg2, h, rec_etdint, pk)
    #if debug: print("new randomness =>", r1)
    new_h = {
        'h': h['h'],
        'r': r1,
        'cipher': h['cipher'],
        'N1': h['N1'],
        'e': h['e']
    }
    return new_h
コード例 #11
0
 def decrypt(self, pk, sk, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = abenc.decrypt(pk, sk, c1)
     if key is False:
         print ("[WARNING] key failed to decrypt, message not intented for this device.")
         return None
     cipher = AuthenticatedCryptoAbstraction(sha2(key))
     return cipher.decrypt(c2)
コード例 #12
0
ファイル: symcrypto_test.py プロジェクト: FinalF/charm
 def MsgTestAESCBCSeperate(self,msg):
     groupObj = PairingGroup('SS512')
     ran = groupObj.random(GT)
     a =  AuthenticatedCryptoAbstraction(sha1(ran))
     ct = a.encrypt(msg)        
     b =  AuthenticatedCryptoAbstraction(sha1(ran))
     dmsg = b.decrypt(ct);
     assert msg == dmsg , 'o: =>%s\nm: =>%s' % (msg, dmsg)
コード例 #13
0
 def decrypt(self, pk, sk, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = self.pkenc.decrypt(pk, sk, c1)[:self.key_len]
     if debug: print("Rec key =>", key, ", len =", len(key))
     cipher = AuthenticatedCryptoAbstraction(key)
     msg = cipher.decrypt(c2)
     if debug: print("Rec msg =>", msg)
     return msg
コード例 #14
0
ファイル: pkenc_adapt_hybrid.py プロジェクト: FinalF/charm
 def decrypt(self, pk, sk, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = self.pkenc.decrypt(pk, sk, c1)[:self.key_len]
     if debug: print("Rec key =>", key,", len =", len(key))
     cipher = AuthenticatedCryptoAbstraction(key)
     msg = cipher.decrypt(c2)
     if debug: print("Rec msg =>", msg)
     return msg
コード例 #15
0
ファイル: ibenc_adapt_hybrid.py プロジェクト: FinalF/charm
 def encrypt(self, pk, ID, M):
     if type(M) != bytes: raise "message not right type!"        
     key = group.random(GT)
     c1 = ibenc.encrypt(pk, ID, key)
     # instantiate a symmetric enc scheme from this key
     cipher = AuthenticatedCryptoAbstraction(sha1(key))
     c2 = cipher.encrypt(M)
     return { 'c1':c1, 'c2':c2 }
コード例 #16
0
ファイル: dabenc_adapt_hybrid.py プロジェクト: FinalF/charm
 def encrypt(self, pk, gp, M, policy_str):
     if type(M) != bytes and type(policy_str) != str: raise "message and policy not right type!"        
     key = group.random(GT)
     c1 = abencma.encrypt(pk, gp, key, policy_str)
     # instantiate a symmetric enc scheme from this key
     cipher = AuthenticatedCryptoAbstraction(sha1(key)) 
     c2 = cipher.encrypt(M)
     return { 'c1':c1, 'c2':c2 }
コード例 #17
0
 def encrypt_jet(self, params, ID, M):
     if type(M) != bytes: raise "Type ERROR: Message should be bytes."
     key = group.random(GT)
     c1 = self.encrypt(params, ID, key)
     # instantiate a symmetric enc scheme from this key
     cipher = AuthenticatedCryptoAbstraction(sha1(key))
     c2 = cipher.encrypt(M)
     return {'c1': c1, 'c2': c2}
コード例 #18
0
ファイル: sub.py プロジェクト: SNET-Entrance/gc_for_pubsub
 def decAes(self, CT):
     if self.dek is None:
         raise Exception('DEK is null, cannot decrypt')
     
     
     a = AuthenticatedCryptoAbstraction(bytes(self.dek, "utf-8"))
     #CT_AES = a.encrypt(message)
     return a.decrypt(CT)
コード例 #19
0
 def encrypt(self, pk, ID, M):
     if type(M) != bytes: raise "message not right type!"
     key = group.random(GT)
     c1 = ibenc.encrypt(pk, ID, key)
     # instantiate a symmetric enc scheme from this key
     cipher = AuthenticatedCryptoAbstraction(sha2(key))
     c2 = cipher.encrypt(M)
     return {'c1': c1, 'c2': c2}
コード例 #20
0
ファイル: IBRS.py プロジェクト: IBRS4VANETs/TEST-CASEs
 def parseList(self, packet, rpk):
   if packet.flag:
     symKey = hashlib.sha256(self.group.serialize(pair(self.sk, rpk))).digest()
     cipherRuner = AuthenticatedCryptoAbstraction(symKey)
     payload = cipherRuner.decrypt(packet.payload)
     L = json.loads(payload)
     return L
   else:
     raise "Banned!"
コード例 #21
0
    def encAES(self, m):
        if self.dek is None:
            raise Exception('DEK is null, cannot encrypt')

        a = AuthenticatedCryptoAbstraction(bytes(self.dek, "utf-8"))
        CT_AES = a.encrypt(m)
        groupObj = PairingGroup('SS512')

        return objectToBytes(CT_AES, groupObj)
コード例 #22
0
 def encrypt(self, pk, gp, M, policy_str):
     if type(M) != bytes and type(policy_str) != str:
         raise "message and policy not right type!"
     key = group.random(GT)
     c1 = abencma.encrypt(pk, gp, key, policy_str)
     # instantiate a symmetric enc scheme from this key
     cipher = AuthenticatedCryptoAbstraction(sha1(key))
     c2 = cipher.encrypt(M)
     return {'c1': c1, 'c2': c2}
コード例 #23
0
def decryptAES(readFileCipherText, keyAES):
    pickleFileCipherText = pickleLoad(readFileCipherText)
    ct = byToOb(pickleFileCipherText)

    symcrypt = AuthenticatedCryptoAbstraction(extractor(keyAES))
    recoveredMsg = symcrypt.decrypt(ct)
    print("Decrypted File using AES:")
    print(recoveredMsg.decode("utf-8"))
    return recoveredMsg
コード例 #24
0
	def encrypt(self, plaintext, policy):
		#return self.cpabe.encrypt(self.public, plaintext, policy)
		key = self.groupObj.random(GT)
		c1 = self.cpabe.encrypt(self.public, key, policy)

        # instantiate a symmetric enc scheme from this key
		cipher = AuthenticatedCryptoAbstraction(sha1(key))
		c2 = cipher.encrypt(plaintext)
		return { 'c1':c1, 'c2':c2 }
コード例 #25
0
ファイル: IBRS.py プロジェクト: IBRS4VANETs/TEST-CASEs
 def v2i(self,rpk):
   r = self.group.random(ZR)
   g_r = pair(self.mpk, rpk) ** r
   V = integer(self.group.serialize(self.pk)) ^ integer(self.group.serialize(g_r))
   mPath = [str(x.value) for x in self.path]
   message = json.dumps(mPath)
   symKey = hashlib.sha256(self.group.serialize(pair(self.sk, rpk))).digest()
   cipherRuner = AuthenticatedCryptoAbstraction(symKey)
   cPath = cipherRuner.encrypt(message)
   return (r * self.P, V, cPath)
コード例 #26
0
 def encrypt(self, pk, M):
     # generate a short session key, K and encrypt using pkenc
     key = OpenSSLRand().getRandomBytes(self.key_len)
     # encrypt session key using PKEnc
     c1 = self.pkenc.encrypt(pk, key)
     # use symmetric key encryption to enc actual message
     cipher = AuthenticatedCryptoAbstraction(key)
     c2 = cipher.encrypt(M)
     if debug: print("Ciphertext 2...")
     if debug: print(c2)
     return {'c1': c1, 'c2': c2}
コード例 #27
0
	def encrypt(self, plaintext, policy):
		''' Encrypt a block of plaintext using the provided polcy structure. 
		The ciphertext is stored as a dictionary, for now.
		'''
		key = self.groupObj.random(GT)
		c1 = self.cpabe.encrypt(self.public, key, policy)

        # Instantiate a symmetric enc scheme from this key
		cipher = AuthenticatedCryptoAbstraction(sha1(key))
		c2 = cipher.encrypt(plaintext)
		return objectToBytes({ 'c1':c1, 'c2':c2 }, self.groupObj)
コード例 #28
0
ファイル: pkenc_adapt_hybrid.py プロジェクト: FinalF/charm
 def encrypt(self, pk, M):
     # generate a short session key, K and encrypt using pkenc
     key = OpenSSLRand().getRandomBytes(self.key_len) # urandom(self.key_len)
     # encrypt session key using PKEnc
     c1 = self.pkenc.encrypt(pk, key)
     # use symmetric key encryption to enc actual message
     cipher = AuthenticatedCryptoAbstraction(key)
     c2 = cipher.encrypt(M)
     if debug: print("Ciphertext 2...")
     if debug: print(c2)
     return { 'c1':c1, 'c2':c2 }
コード例 #29
0
	def decrypt(self, sKey, ciphertext):
		#return self.cpabe.decrypt(self.public, sKey, ciphertext)
		c1, c2 = ciphertext['c1'], ciphertext['c2']
		success = True

		# TODO: we need to supress the print statement that comes out of this guy, to avoid unnecessary events
		try:
			key = self.cpabe.decrypt(self.public, sKey, c1)
			if (key == False):
				success = False
		except: 
			success = False

		# Try to perform the encryption if we were able to recover the key
		plaintext = None
		if (success == True):
			cipher = AuthenticatedCryptoAbstraction(sha1(key))
			plaintext = cipher.decrypt(c2)
		return (success, plaintext)
コード例 #30
0
	def decrypt(self, sKey, serializedCiphertext):
		''' Decrypt the provided ciphertext sing the secret key. Decryption is only successful if
		the policy embedded in the secret key matches the ciphertext access policy.
		'''
		ciphertext = bytesToObject(serializedCiphertext, PairingGroup('SS512'))
		c1, c2 = ciphertext['c1'], ciphertext['c2']
		success = True
		try:
			key = self.cpabe.decrypt(self.public, sKey, c1)
			if (key == False):
				success = False
		except: 
			success = False

		# Try to perform the decryption if we were able to recover the key
		plaintext = None
		if (success == True):
			cipher = AuthenticatedCryptoAbstraction(sha1(key))
			plaintext = cipher.decrypt(c2)
		return (success, plaintext)
コード例 #31
0
ファイル: symcrypto_test.py プロジェクト: ztm1992/charm
 def MsgTestAESCBCSeperate(self, msg):
     groupObj = PairingGroup('SS512')
     ran = groupObj.random(GT)
     a = AuthenticatedCryptoAbstraction(sha1(ran))
     ct = a.encrypt(msg)
     b = AuthenticatedCryptoAbstraction(sha1(ran))
     dmsg = b.decrypt(ct)
     assert msg == dmsg, 'o: =>%s\nm: =>%s' % (msg, dmsg)
コード例 #32
0
ファイル: IBRS.py プロジェクト: IBRS4VANETs/TEST-CASEs
  def i2v(self, CList, kunodes):
    Package = namedtuple('Package', 'destination payload flag')
    dataStream = []
    candidate = []
    pseuIDs = []
    flags = []
    tempRunner = []


    for ct in CList:
      U = ct[0]
      V = ct[1]

      pseuID = self.group.deserialize( int2Bytes( V ^ integer(self.group.serialize(pair(U, self.sk)))))
      symKey = hashlib.sha256(self.group.serialize(pair(pseuID, self.sk))).digest()
      cipherRuner = AuthenticatedCryptoAbstraction(symKey)
      tempRunner.append(cipherRuner)
      pathList = json.loads(cipherRuner.decrypt(ct[2]))
      pathValue = [int(x) for x in pathList]

      tempFlag = set(pathValue) & kunodes
      flags.append(bool(tempFlag))
      pseuIDs.append(pseuID)

      if tempFlag:
        candidate.append(str(self.group.serialize(pseuID), encoding = 'utf-8'))
      # dataStream.append(Package(pseuID, '', set(pathValue) & kunodes))

    for index, pid in enumerate(pseuIDs):
      if flags[index]:        
        payload = tempRunner[index].encrypt(json.dumps(candidate))
        dataStream.append(Package(pid, payload, flags[index]))
      else:
        dataStream.append(Package(pid, 'You are blocked', flags[index]))

    return dataStream
コード例 #33
0
 def decrypt(self, gp, sk, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = abencma.decrypt(gp, sk, c1)
     cipher = AuthenticatedCryptoAbstraction(sha1(key))
     return cipher.decrypt(c2)
コード例 #34
0
ファイル: Encrypt.py プロジェクト: mmlab-aueb/IB-PRE-APP
from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction
from charm.toolbox.securerandom import OpenSSLRand

ID = sys.argv[1]
file_name = sys.argv[2]
'''Group set up'''
group = PairingGroup('SS512', secparam=1024)
ibp = PreGA(group)
f = open('./setup/master.param', 'r')
bin_data = f.read()
params = bytesToObject(bin_data, group)
f.close()
''' End set up'''
'''Symmetric encryption key and algorithm set up'''
sym_key = OpenSSLRand().getRandomBytes(16)
sym_cipher = AuthenticatedCryptoAbstraction(sym_key)
'''End set up'''
'''Encryption proccess'''
sym_key_ciphertext = ibp.encrypt(params, ID, sym_key)
# encrypt the symmetric encryption key
f = open(file_name, 'r')
file_data = f.read()
file_ciphertext = sym_cipher.encrypt(file_data)
'''End of encryption process'''

ct = {
    'CA': objectToBytes(sym_key_ciphertext['C']['A'], group),
    'CB': objectToBytes(sym_key_ciphertext['C']['B'], group),
    'CC': objectToBytes(sym_key_ciphertext['C']['C'], IntegerGroup()),
    'S': objectToBytes(sym_key_ciphertext['S'], group),
    'Data': file_ciphertext
コード例 #35
0
ファイル: symcrypto_test.py プロジェクト: ztm1992/charm
 def MsgtestAESCBC(self, msg):
     groupObj = PairingGroup('SS512')
     a = AuthenticatedCryptoAbstraction(sha1(groupObj.random(GT)))
     ct = a.encrypt(msg)
     dmsg = a.decrypt(ct)
     assert msg == dmsg, 'o: =>%s\nm: =>%s' % (msg, dmsg)
コード例 #36
0
ファイル: MAPCH.py プロジェクト: leuitong/Redactable-fabric
def main():
    groupObj = PairingGroup('SS512')

    maabe = MAABE.MaabeRW15(groupObj)
    attrs1 = ['ONE', 'TWO']
    attrs2 = ['THREE', 'FOUR']

    access_policy = '((STUDENT@UT or PROFESSOR@OU) and (STUDENT@UT or MASTERS@OU))'
    if debug:
        print("attrs1 =>", attrs1)
        print("attrs2 =>", attrs2)
        print("Policy =>", access_policy)

    # setup
    public_parameters = maabe.setup()

    # authsetup 2AA
    (pk1, sk1) = maabe.authsetup(public_parameters, 'UT')
    (pk2, sk2) = maabe.authsetup(public_parameters, 'OU')
    maabepk = {'UT': pk1, 'OU': pk2}

    # keygen
    chamHash = chamwithemp.Chamwithemp()
    (pk, sk) = chamHash.keygen(1024)

    # keygen Bob
    gid = "bob"
    user_attr1 = ['STUDENT@UT']
    user_attr2 = ['STUDENT@OU']

    user_sk1 = maabe.multiple_attributes_keygen(public_parameters, sk1, gid,
                                                user_attr1)
    user_sk2 = maabe.multiple_attributes_keygen(public_parameters, sk2, gid,
                                                user_attr2)

    user_sk = {'GID': gid, 'keys': merge_dicts(user_sk1, user_sk2)}

    # hash
    msg = "Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for t"
    xi = chamHash.hash(pk, msg)
    etd = [xi['p1'], xi['q1']]
    if debug: print("Hash...")
    if debug: print("hash result =>", xi)

    # encrypt
    rand_key = groupObj.random(GT)
    if debug: print("msg =>", rand_key)
    #encrypt rand_key
    maabect = maabe.encrypt(public_parameters, maabepk, rand_key,
                            access_policy)
    #rand_key->symkey AE
    symcrypt = AuthenticatedCryptoAbstraction(extractor(rand_key))
    #symcrypt msg(etd=(p1,q1))
    etdtostr = [str(i) for i in etd]
    etdsumstr = etdtostr[0] + etdtostr[1]
    symct = symcrypt.encrypt(etdsumstr)

    ct = {'rkc': maabect, 'ec': symct}

    if debug: print("\n\nCiphertext...\n")
    groupObj.debug(ct)
    print("ciphertext:=>", ct)

    # decrypt
    #decrypt rand_key
    rec_key = maabe.decrypt(public_parameters, user_sk, maabect)
    assert rand_key == rec_key, "FAILED Decryption: random key is incorrect"
    #rec_key->symkey AE
    rec_symcrypt = AuthenticatedCryptoAbstraction(extractor(rec_key))
    #symdecrypt rec_etdsumstr
    rec_etdsumbytes = rec_symcrypt.decrypt(ct['ec'])
    rec_etdsumstr = str(rec_etdsumbytes, encoding="utf8")
    print("etdsumstr type=>", type(rec_etdsumstr))
    #sumstr->etd str list
    rec_etdtolist = cut_text(rec_etdsumstr, len(etdtostr[0]))
    print("rec_etdtolist=>", rec_etdtolist)
    #etd str list->etd integer list
    rec_etdint = [
        integer(int(rec_etdtolist[0])),
        integer(int(rec_etdtolist[1]))
    ]
    print("rec_etdint=>", rec_etdint)

    if debug: print("\n\nDecrypt...\n")
    if debug: print("Successful Decryption!!!")

    # collision
    msg1 = "Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for p"
    assert xi['p1'] == rec_etdint[
        0], "FAILED Decryption: etd key p1 is incorrect"
    assert xi['q1'] == rec_etdint[
        1], "FAILED Decryption: etd key q1 is incorrect"
    r1 = chamHash.collision(msg, msg1, xi, sk, pk)
    if debug: print("new randomness =>", r1)

    if debug: print("collision generated correctly!!!")
コード例 #37
0
ファイル: dabenc_adapt_hybrid.py プロジェクト: FinalF/charm
 def decrypt(self, gp, sk, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = abencma.decrypt(gp, sk, c1)
     cipher = AuthenticatedCryptoAbstraction(sha1(key))
     return cipher.decrypt(c2)
コード例 #38
0
ファイル: ibenc_adapt_hybrid.py プロジェクト: FinalF/charm
 def decrypt(self, pk, ID, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = ibenc.decrypt(pk, ID, c1)        
     cipher = AuthenticatedCryptoAbstraction(sha1(key))
     return cipher.decrypt(c2)
コード例 #39
0
 def decrypt(self, ct, sk):
     c1, c2 = ct['c1'], ct['c2']
     key = abenc.decrypt(c1, sk)
     cipher = AuthenticatedCryptoAbstraction(extract_key(key))
     return cipher.decrypt(c2)
コード例 #40
0
ファイル: kpabenc_adapt_hybrid.py プロジェクト: FinalF/charm
 def decrypt(self, ct, sk):
     c1, c2 = ct['c1'], ct['c2']
     key = abenc.decrypt(c1, sk)
     cipher = AuthenticatedCryptoAbstraction(sha1(key))
     return cipher.decrypt(c2)
コード例 #41
0
params = bytesToObject(bin_data, group)
''' End set up'''
''' Load user key'''
f = open('./userkeys/' + ID + '.key', 'r')
bin_data = f.read()
id_secret_key = bytesToObject(bin_data, group)
f.close()
''' End loading user key '''
''' Load ciphertexts '''
f = open('./ciphertexts/' + ID + file_name + '.enc', 'r')
bin_data = f.readline()
ct = json.loads(bin_data)
A = bytesToObject(ct['CA'], group)
B = bytesToObject(ct['CB'], group)
C = bytesToObject(ct['CC'], IntegerGroup())
S = bytesToObject(ct['S'], group)
C_ = {'A': A, 'B': B, 'C': C}
encr_key = {'S': S, 'C': C_}
ciphertext = ct['Data']
f.close()
''' End loading ciphertexts '''
'''Symmetric encryption key and algorithm set up'''
sym_key = ibp.decryptFirstLevel(params, id_secret_key, encr_key, ID)
sym_cipher = AuthenticatedCryptoAbstraction(sym_key)
'''End set up'''
''' File decyption process '''
file_decrypted = sym_cipher.decrypt(ciphertext)
f = open('./plaintexts/' + file_name, 'w')
f.write(file_decrypted)
f.close()
コード例 #42
0
    def decrypt_jet(self, params, skid, cid):
        c1, c2 = cid['c1'], cid['c2']
        key = self.decrypt(params, skid, c1)

        cipher = AuthenticatedCryptoAbstraction(sha1(key))
        return cipher.decrypt(c2)
コード例 #43
0
from charm.toolbox.pairinggroup import PairingGroup, ZR, G1, G2, GT, pair
from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction, SymmetricCryptoAbstraction
from charm.core.math.pairing import hashPair as extractor
from CPabe09 import CPabe09


group = PairingGroup("SS512")

# use random pairing to encrypt byte message
pairing = group.random(GT)
msg = b"This is a secret message that is larger than the group elements and has to be encrypted symmetrically"

# extractor can cope with multiple datatypes, actually its just a hash function
symcrypt_sender = AuthenticatedCryptoAbstraction(extractor(pairing))

# setup cp-abe
g1, g2 = group.random(G1), group.random(G2)
alpha, a = group.random(), group.random()
cpabe = CPabe09(group)
(master_secret_key, master_public_key) = cpabe.setup(g1, g2, alpha, a)

# set up the policy for abe
policy = '((ONE or THREE) and (TWO or FOUR))'

# define the attributes for abe
attr_list = ['ONE', 'TWO', 'THREE']

# get the secret key for abe
secret_key = cpabe.keygen(master_public_key, master_secret_key, attr_list)

コード例 #44
0
ファイル: symcrypto_test.py プロジェクト: FinalF/charm
 def MsgtestAESCBC(self,msg):
     groupObj = PairingGroup('SS512')
     a =  AuthenticatedCryptoAbstraction(sha1(groupObj.random(GT)))
     ct = a.encrypt(msg)
     dmsg = a.decrypt(ct);
     assert msg == dmsg , 'o: =>%s\nm: =>%s' % (msg, dmsg)
コード例 #45
0
 (serPKr, serMKr, conversionFactor) = W.refresh(serPK, serMK)
 #refresh one more time :)
 print(conversionFactor)
 (serPKr, serMKr, conversionFactor) = W.refresh(serPK, serMK)
 print(conversionFactor)
 (serPKr, serMKr, conversionFactor) = W.refresh(serPK, serMK)
 print(conversionFactor)
 (serPKr, serMKr, conversionFactor) = W.refresh(serPK, serMK)
 print(conversionFactor)
 serSKr = W.refreshSK(serSK, conversionFactor)
 newCT = W.encrypt(serPKr, message, access_policy)
 print("ratchat applied and the message is encrypted by conversed SK")
 try:
     mdec = W.decrypt(serPK, serSK, newCT)
 except ValueError as e:
     print("good: got ValueError, when trying to decrypt with the old key: " + repr(e))
     
 newMdec = W.decrypt(serPKr, serSKr, newCT)
 assert mdec == message, "Failed Decryption!!!"
 print("done: ABE - ratchet")
 
 #--------
 DEK = W.getDEK()
 
 from charm.toolbox.symcrypto import AuthenticatedCryptoAbstraction
 a = AuthenticatedCryptoAbstraction(DEK)
 CT_AES = a.encrypt(message)
 mdec = a.decrypt(CT_AES)
 assert mdec == message, "Failed Decryption!!!"
 print("done: AES")
 
コード例 #46
0
 def decrypt(self, pk, ID, ct):
     c1, c2 = ct['c1'], ct['c2']
     key = ibenc.decrypt(pk, ID, c1)
     cipher = AuthenticatedCryptoAbstraction(sha2(key))
     return cipher.decrypt(c2)