当前位置: 首页>>代码示例>>Python>>正文


Python AES.MODE_ECB属性代码示例

本文整理汇总了Python中Crypto.Cipher.AES.MODE_ECB属性的典型用法代码示例。如果您正苦于以下问题:Python AES.MODE_ECB属性的具体用法?Python AES.MODE_ECB怎么用?Python AES.MODE_ECB使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在Crypto.Cipher.AES的用法示例。


在下文中一共展示了AES.MODE_ECB属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decrypt

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def decrypt(self, data):
		key = self.session.get_session_key()
		
		method = self.settings.get("pia.encryption_method")
		if method == EncryptionMethod.AES_ECB:
			aes = AES.new(key, AES.MODE_ECB)
			return aes.decrypt(data)
		else:
			nonce = self.session.generate_nonce(self)
			aes = AES.new(key, AES.MODE_GCM, nonce=nonce)
			try:
				data = aes.decrypt_and_verify(data, self.signature)
			except ValueError:
				logger.warning("Received incorrect AES-GCM tag")
				return None
			return data 
开发者ID:Kinnay,项目名称:NintendoClients,代码行数:18,代码来源:packet.py

示例2: decrypt_lsa_key_nt6

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def decrypt_lsa_key_nt6(lsakey, syskey):
	"""
	This function decrypts the LSA keys using the syskey
	"""
	dg = hashlib.sha256()
	dg.update(syskey)
	for i in xrange(1000):
		dg.update(lsakey[28:60])
	keys = AES.new(dg.digest(), AES.MODE_ECB).decrypt(lsakey[60:])
	size = struct.unpack_from("<L", keys)[0]
	keys = keys[16:16 + size]
	currentkey = "%0x-%0x-%0x-%0x%0x-%0x%0x%0x%0x%0x%0x" % struct.unpack("<L2H8B", keys[4:20])
	nb = struct.unpack("<L", keys[24:28])[0]
	off = 28
	kd = {}
	for i in xrange(nb):
		g = "%0x-%0x-%0x-%0x%0x-%0x%0x%0x%0x%0x%0x" % struct.unpack("<L2H8B", keys[off:off + 16])
		t, l = struct.unpack_from("<2L", keys[off + 16:])
		k = keys[off + 24:off + 24 + l]
		kd[g] = {"type": t, "key": k}
		off += 24 + l
	return (currentkey, kd) 
开发者ID:AlessandroZ,项目名称:LaZagneForensic,代码行数:24,代码来源:crypto.py

示例3: decrypt_lsa_secret

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def decrypt_lsa_secret(secret, lsa_keys):
	"""
	This function replaces SystemFunction005 for newer Windows
	"""
	keyid = "%0x-%0x-%0x-%0x%0x-%0x%0x%0x%0x%0x%0x" % struct.unpack("<L2H8B", secret[4:20])
	if keyid not in lsa_keys:
		return None
	algo = struct.unpack("<L", secret[20:24])[0]
	dg = hashlib.sha256()
	dg.update(lsa_keys[keyid]["key"])
	for i in xrange(1000):
		dg.update(secret[28:60])

	clear = AES.new(dg.digest(), AES.MODE_ECB).decrypt(secret[60:])
	size = struct.unpack_from("<L", clear)[0]
	return clear[16:16 + size] 
开发者ID:AlessandroZ,项目名称:LaZagneForensic,代码行数:18,代码来源:crypto.py

示例4: encryption_oracle_aes

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def encryption_oracle_aes(payload):
    global constant, prefix_len, suffix_len, secret
    if secret:
        if constant:
            payload = random_bytes(prefix_len) + payload + secret
        else:
            payload = random_bytes(random.randint(1, 50)) + payload + secret
    else:
        if constant:
            payload = random_bytes(prefix_len) + payload + random_bytes(suffix_len)
        else:
            payload = random_bytes(random.randint(1, 50)) + payload + random_bytes(random.randint(1, 50))

    payload = add_padding(payload, AES.block_size)
    cipher = AES.new(key_AES, AES.MODE_ECB)
    return cipher.encrypt(payload) 
开发者ID:GrosQuildu,项目名称:CryptoAttacks,代码行数:18,代码来源:test_ecb.py

示例5: encryption_oracle_des

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def encryption_oracle_des(payload):
    global constant, prefix_len, suffix_len, secret
    if secret:
        if constant:
            payload = random_bytes(prefix_len) + payload + secret
        else:
            payload = random_bytes(random.randint(1, 50)) + payload + secret
    else:
        if constant:
            payload = random_bytes(prefix_len) + payload + random_bytes(suffix_len)
        else:
            payload = random_bytes(random.randint(1, 50)) + payload + random_bytes(random.randint(1, 50))

    payload = add_padding(payload, DES3.block_size)
    cipher = DES3.new(key_DES3, DES3.MODE_ECB)
    return cipher.encrypt(payload) 
开发者ID:GrosQuildu,项目名称:CryptoAttacks,代码行数:18,代码来源:test_ecb.py

示例6: change_key

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def change_key(self, master_key):
                if master_key >= (1 << 128):
                    raise InvalidInputException('Master key should be 128-bit')

                self.__master_key = long_to_bytes(master_key, 16)
                self.__aes_ecb = AES.new(self.__master_key, AES.MODE_ECB)
                self.__auth_key = bytes_to_long(self.__aes_ecb.encrypt(b'\x00' * 16))

                # precompute the table for multiplication in finite field
                table = []  # for 8-bit
                for i in range(16):
                    row = []
                    for j in range(256):
                        row.append(self.gf_2_128_mul(self.__auth_key, j << (8 * i)))
                    table.append(tuple(row))
                self.__pre_table = tuple(table)

                self.prev_init_value = None  # reset 
开发者ID:bkerler,项目名称:edl,代码行数:20,代码来源:cryptutils.py

示例7: main

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def main():
    with open(F,'r') as f:
      b64 = f.read()
      enc = tools.fromB64(b64)
    
    encBlocks = tools.split(enc, 16, False)

    iv = IV
    result = b''
    
    cipher=AES.new(KEY, AES.MODE_ECB)
    
    for block in encBlocks:
      decBlock = cipher.decrypt(block)
      dec = crypto.xor(decBlock, iv)
      iv = block
      result += dec
    
    print(tools.toStr(tools.stripPadding(result))) 
开发者ID:anomen-s,项目名称:programming-challenges,代码行数:21,代码来源:solve.py

示例8: __init__

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def __init__(self, key):
        super().__init__(AES.new(key, AES.MODE_ECB)) 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:4,代码来源:pycrypto.py

示例9: _aes_decrypt

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def _aes_decrypt(aes_key, aes_text) -> Text:
    """
    使用密钥解密文本信息,将会自动填充空白字符
    :param aes_key: 解密密钥
    :param aes_text: 需要解密的文本
    :return: 经过解密的数据
    """
    # 初始化解码器
    cipher = AES.new(_fill_16(aes_key), AES.MODE_ECB)
    # 优先逆向解密十六进制为bytes
    converted = a2b_base64(aes_text.replace('-', '/').replace("%3D", "=").encode())
    # 使用aes解密密文
    decrypt_text = str(cipher.decrypt(converted), encoding='utf-8').replace('\0', '')
    # 返回执行结果
    return decrypt_text.strip() 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:17,代码来源:encryption.py

示例10: _aes_encrypt

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def _aes_encrypt(aes_key, aes_text) -> Text:
    """
    使用密钥加密文本信息,将会自动填充空白字符
    :param aes_key: 加密密钥
    :param aes_text: 需要加密的文本
    :return: 经过加密的数据
    """
    # 初始化加密器
    cipher = AES.new(_fill_16(aes_key), AES.MODE_ECB)
    # 先进行aes加密
    aes_encrypted = cipher.encrypt(_fill_16(aes_text))
    # 使用十六进制转成字符串形式
    encrypt_text = b2a_base64(aes_encrypted).decode().replace('/', '-').strip()
    # 返回执行结果
    return encrypt_text 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:17,代码来源:encryption.py

示例11: decrypt

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def decrypt(self, hex):
        encoded = binascii.unhexlify(hex)
        secret = self.get_secret()
        BLOCK_SIZE = 16
        mode = AES.MODE_ECB
        cipher = AES.new(secret, mode)
        return cipher.decrypt(encoded).split('\x00')[0] 
开发者ID:mehulj94,项目名称:Radium,代码行数:9,代码来源:Coreftp.py

示例12: aes

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def aes(self):
        return AES.new(self.key, AES.MODE_ECB) # 初始化加密器 
开发者ID:inlike,项目名称:R-A-M-D-D3-S-M-H,代码行数:4,代码来源:RSA-AES-MD5-DES-DES3-MD5-SHA-HMAC.py

示例13: GetDeviceKey

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def GetDeviceKey(self):
        _LOGGER.info('Retrieving HVAC encryption key')
        GENERIC_GREE_DEVICE_KEY = "a3K8Bx%2r8Y7#xDh"
        cipher = AES.new(GENERIC_GREE_DEVICE_KEY.encode("utf8"), AES.MODE_ECB)
        pack = base64.b64encode(cipher.encrypt(self.Pad('{"mac":"' + str(self._mac_addr) + '","t":"bind","uid":0}').encode("utf8"))).decode('utf-8')
        jsonPayloadToSend = '{"cid": "app","i": 1,"pack": "' + pack + '","t":"pack","tcid":"' + str(self._mac_addr) + '","uid": 0}'
        return self.FetchResult(cipher, self._ip_addr, self._port, self._timeout, jsonPayloadToSend)['key'] 
开发者ID:RobHofmann,项目名称:HomeAssistant-GreeClimateComponent,代码行数:9,代码来源:climate.py

示例14: aes_unwrap_key_and_iv

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def aes_unwrap_key_and_iv(kek, wrapped):
    n = len(wrapped)//8 - 1
    #NOTE: R[0] is never accessed, left in for consistency with RFC indices
    R = [None]+[wrapped[i*8:i*8+8] for i in range(1, n+1)]
    A = QUAD.unpack(wrapped[:8])[0]
    decrypt = AES.new(kek, AES.MODE_ECB).decrypt
    for j in range(5,-1,-1): #counting down
        for i in range(n, 0, -1): #(n, n-1, ..., 1)
            ciphertext = QUAD.pack(A^(n*j+i)) + R[i]
            B = decrypt(ciphertext)
            A = QUAD.unpack(B[:8])[0]
            R[i] = B[8:]
    return b"".join(R[1:]), A 
开发者ID:aff4,项目名称:pyaff4,代码行数:15,代码来源:aes_keywrap.py

示例15: aes_unwrap_key_withpad

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_ECB [as 别名]
def aes_unwrap_key_withpad(kek, wrapped):
    '''
    alternate initial value for aes key wrapping, as defined in RFC 5649 section 3
    http://www.ietf.org/rfc/rfc5649.txt
    '''
    if len(wrapped) == 16:
        plaintext = AES.new(kek, AES.MODE_ECB).decrypt(wrapped)
        key, key_iv = plaintext[:8], plaintext[8:]
    else:
        key, key_iv = aes_unwrap_key_and_iv(kek, wrapped)
    key_iv = "{0:016X}".format(key_iv)
    if key_iv[:8] != "A65959A6":
        raise ValueError("Integrity Check Failed: "+key_iv[:8]+" (expected A65959A6)")
    key_len = int(key_iv[8:], 16)
    return key[:key_len] 
开发者ID:aff4,项目名称:pyaff4,代码行数:17,代码来源:aes_keywrap.py


注:本文中的Crypto.Cipher.AES.MODE_ECB属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。