當前位置: 首頁>>代碼示例>>Python>>正文


Python AES.MODE_ECB屬性代碼示例

本文整理匯總了Python中Cryptodome.Cipher.AES.MODE_ECB屬性的典型用法代碼示例。如果您正苦於以下問題:Python AES.MODE_ECB屬性的具體用法?Python AES.MODE_ECB怎麽用?Python AES.MODE_ECB使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在Cryptodome.Cipher.AES的用法示例。


在下文中一共展示了AES.MODE_ECB屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: decode_aes256

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def decode_aes256(cipher, iv, data, encryption_key):
    """
    Decrypt AES-256 bytes.
    Allowed ciphers are: :ecb, :cbc.
    If for :ecb iv is not used and should be set to "".
    """
    if cipher == 'cbc':
        aes = AES.new(encryption_key, AES.MODE_CBC, iv)
    elif cipher == 'ecb':
        aes = AES.new(encryption_key, AES.MODE_ECB)
    else:
        raise ValueError('Unknown AES mode')
    d = aes.decrypt(data)
    # http://passingcuriosity.com/2009/aes-encryption-in-python-with-m2crypto/
    unpad = lambda s: s[0:-ord(d[-1:])]
    return unpad(d) 
開發者ID:Keeper-Security,項目名稱:Commander,代碼行數:18,代碼來源:parser.py

示例2: decryptSecret

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def decryptSecret(key, value):
    # [MS-LSAD] Section 5.1.2
    plainText = b''
    key0 = key
    for i in range(0, len(value), 8):
        cipherText = value[:8]
        tmpStrKey = key0[:7]
        tmpKey = transformKey(tmpStrKey)
        Crypt1 = DES.new(tmpKey, DES.MODE_ECB)
        plainText += Crypt1.decrypt(cipherText)
        key0 = key0[7:]
        value = value[8:]
        # AdvanceKey
        if len(key0) < 7:
            key0 = key[len(key0):]

    secret = LSA_SECRET_XP(plainText)
    return (secret['Secret']) 
開發者ID:Coalfire-Research,項目名稱:Slackor,代碼行數:20,代碼來源:crypto.py

示例3: encryptSecret

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def encryptSecret(key, value):
    # [MS-LSAD] Section 5.1.2
    cipherText = b''
    key0 = key
    value0 = pack('<LL', len(value), 1) + value
    for i in range(0, len(value0), 8):
        if len(value0) < 8:
            value0 = value0 + b'\x00'*(8-len(value0))
        plainText = value0[:8]
        tmpStrKey = key0[:7]
        print(type(tmpStrKey))
        print(tmpStrKey)
        tmpKey = transformKey(tmpStrKey)
        Crypt1 = DES.new(tmpKey, DES.MODE_ECB)
        cipherText += Crypt1.encrypt(plainText)
        key0 = key0[7:]
        value0 = value0[8:]
        # AdvanceKey
        if len(key0) < 7:
            key0 = key[len(key0):]

    return cipherText 
開發者ID:Coalfire-Research,項目名稱:Slackor,代碼行數:24,代碼來源:crypto.py

示例4: SamDecryptNTLMHash

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def SamDecryptNTLMHash(encryptedHash, key):
    # [MS-SAMR] Section 2.2.11.1.1
    Block1 = encryptedHash[:8]
    Block2 = encryptedHash[8:]

    Key1 = key[:7]
    Key1 = transformKey(Key1)
    Key2 = key[7:14]
    Key2 = transformKey(Key2)

    Crypt1 = DES.new(Key1, DES.MODE_ECB)
    Crypt2 = DES.new(Key2, DES.MODE_ECB)

    plain1 = Crypt1.decrypt(Block1)
    plain2 = Crypt2.decrypt(Block2)

    return plain1 + plain2 
開發者ID:Coalfire-Research,項目名稱:Slackor,代碼行數:19,代碼來源:crypto.py

示例5: SamEncryptNTLMHash

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def SamEncryptNTLMHash(encryptedHash, key):
    # [MS-SAMR] Section 2.2.11.1.1
    Block1 = encryptedHash[:8]
    Block2 = encryptedHash[8:]

    Key1 = key[:7]
    Key1 = transformKey(Key1)
    Key2 = key[7:14]
    Key2 = transformKey(Key2)

    Crypt1 = DES.new(Key1, DES.MODE_ECB)
    Crypt2 = DES.new(Key2, DES.MODE_ECB)

    plain1 = Crypt1.encrypt(Block1)
    plain2 = Crypt2.encrypt(Block2)

    return plain1 + plain2 
開發者ID:Coalfire-Research,項目名稱:Slackor,代碼行數:19,代碼來源:crypto.py

示例6: decryptData

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def decryptData(key, encryptedData):
 """Decrypts the apk data using the specified AES key"""
 aes = AES.new(key, AES.MODE_ECB)
 return b''.join(util.unpad(aes.decrypt(c)) for c in util.chunk(encryptedData, constants.blockSize + constants.paddingSize)) 
開發者ID:ma1co,項目名稱:Sony-PMCA-RE,代碼行數:6,代碼來源:__init__.py

示例7: encryptData

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def encryptData(key, data):
 """Encrypts the apk data using the specified AES key"""
 aes = AES.new(key, AES.MODE_ECB)
 return b''.join(aes.encrypt(util.pad(c, constants.paddingSize)) for c in util.chunk(data, constants.blockSize)) 
開發者ID:ma1co,項目名稱:Sony-PMCA-RE,代碼行數:6,代碼來源:__init__.py

示例8: symmetric_encrypt_ecb

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def symmetric_encrypt_ecb(message, key):
    return AES.new(key, AES.MODE_ECB).encrypt(pad(message)) 
開發者ID:ValvePython,項目名稱:steam,代碼行數:4,代碼來源:crypto.py

示例9: symmetric_encrypt_iv

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def symmetric_encrypt_iv(iv, key):
    return AES.new(key, AES.MODE_ECB).encrypt(iv) 
開發者ID:ValvePython,項目名稱:steam,代碼行數:4,代碼來源:crypto.py

示例10: symmetric_decrypt_ecb

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def symmetric_decrypt_ecb(cyphertext, key):
    return unpad(AES.new(key, AES.MODE_ECB).decrypt(cyphertext)) 
開發者ID:ValvePython,項目名稱:steam,代碼行數:4,代碼來源:crypto.py

示例11: symmetric_decrypt_iv

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def symmetric_decrypt_iv(cyphertext, key):
    return AES.new(key, AES.MODE_ECB).decrypt(cyphertext[:BS]) 
開發者ID:ValvePython,項目名稱:steam,代碼行數:4,代碼來源:crypto.py

示例12: __init__

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def __init__(self, key):
  super(AesCrypter, self).__init__(1024)
  self._cipher = AES.new(key, AES.MODE_ECB) 
開發者ID:ma1co,項目名稱:fwtool.py,代碼行數:5,代碼來源:fdat.py

示例13: aes_kdf

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def aes_kdf(key, rounds, key_composite):
    """Set up a context for AES128-ECB encryption to find transformed_key"""

    cipher = AES.new(key, AES.MODE_ECB)

    # get the number of rounds from the header and transform the key_composite
    transformed_key = key_composite
    for _ in range(0, rounds):
        transformed_key = cipher.encrypt(transformed_key)

    return hashlib.sha256(transformed_key).digest() 
開發者ID:libkeepass,項目名稱:pykeepass,代碼行數:13,代碼來源:common.py

示例14: encrypt

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def encrypt(privkey, passphrase):
    """ BIP0038 non-ec-multiply encryption. Returns BIP0038 encrypted privkey.

    :param privkey: Private key
    :type privkey: Base58
    :param str passphrase: UTF-8 encoded passphrase for encryption
    :return: BIP0038 non-ec-multiply encrypted wif key
    :rtype: Base58

    """
    if isinstance(privkey, str):
        privkey = PrivateKey(privkey)
    else:
        privkey = PrivateKey(repr(privkey))

    privkeyhex = repr(privkey)  # hex
    addr = format(privkey.bitcoin.address, "BTC")
    a = _bytes(addr)
    salt = hashlib.sha256(hashlib.sha256(a).digest()).digest()[0:4]
    if SCRYPT_MODULE == "scrypt":  # pragma: no cover
        key = scrypt.hash(passphrase, salt, 16384, 8, 8)
    elif SCRYPT_MODULE == "pylibscrypt":  # pragma: no cover
        key = scrypt.scrypt(bytes(passphrase, "utf-8"), salt, 16384, 8, 8)
    else:  # pragma: no cover
        raise ValueError("No scrypt module loaded")  # pragma: no cover
    (derived_half1, derived_half2) = (key[:32], key[32:])
    aes = AES.new(derived_half2, AES.MODE_ECB)
    encrypted_half1 = _encrypt_xor(privkeyhex[:32], derived_half1[:16], aes)
    encrypted_half2 = _encrypt_xor(privkeyhex[32:], derived_half1[16:], aes)
    " flag byte is forced 0xc0 because Graphene only uses compressed keys "
    payload = b"\x01" + b"\x42" + b"\xc0" + salt + encrypted_half1 + encrypted_half2
    " Checksum "
    checksum = hashlib.sha256(hashlib.sha256(payload).digest()).digest()[:4]
    privatkey = hexlify(payload + checksum).decode("ascii")
    return Base58(privatkey) 
開發者ID:xeroc,項目名稱:python-graphenelib,代碼行數:37,代碼來源:bip38.py

示例15: decrypt_file

# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def decrypt_file(metadata, encryption_material, in_filename,
                     chunk_size=block_size * 4 * 1024, tmp_dir=None):
        """Decrypts a file and stores the output in the temporary directory.

        Args:
            metadata: The file's metadata input.
            encryption_material: The file's encryption material.
            in_filename: The name of the input file.
            chunk_size: The size of read chunks (Default value = block_size * 4 * 1024).
            tmp_dir: Temporary directory to use, optional (Default value = None).

        Returns:
            The decrypted file's location.
        """
        logger = getLogger(__name__)
        use_openssl_only = os.getenv('SF_USE_OPENSSL_ONLY', 'False') == 'True'
        key_base64 = metadata.key
        iv_base64 = metadata.iv
        decoded_key = base64.standard_b64decode(
            encryption_material.query_stage_master_key)
        key_bytes = base64.standard_b64decode(key_base64)
        iv_bytes = base64.standard_b64decode(iv_base64)

        if not use_openssl_only:
            key_cipher = AES.new(key=decoded_key, mode=AES.MODE_ECB)
            file_key = PKCS5_UNPAD(key_cipher.decrypt(key_bytes))
            data_cipher = AES.new(key=file_key, mode=AES.MODE_CBC, IV=iv_bytes)
        else:
            backend = default_backend()
            cipher = Cipher(algorithms.AES(decoded_key), modes.ECB(), backend=backend)
            decryptor = cipher.decryptor()
            file_key = PKCS5_UNPAD(decryptor.update(key_bytes) + decryptor.finalize())
            cipher = Cipher(algorithms.AES(file_key), modes.CBC(iv_bytes), backend=backend)
            decryptor = cipher.decryptor()

        temp_output_fd, temp_output_file = tempfile.mkstemp(
            text=False, dir=tmp_dir,
            prefix=os.path.basename(in_filename) + "#")
        total_file_size = 0
        prev_chunk = None
        logger.debug('encrypted file: %s, tmp file: %s',
                     in_filename, temp_output_file)
        with open(in_filename, 'rb') as infile:
            with os.fdopen(temp_output_fd, 'wb') as outfile:
                while True:
                    chunk = infile.read(chunk_size)
                    if len(chunk) == 0:
                        break
                    total_file_size += len(chunk)
                    if not use_openssl_only:
                        d = data_cipher.decrypt(chunk)
                    else:
                        d = decryptor.update(chunk)
                    outfile.write(d)
                    prev_chunk = d
                if prev_chunk is not None:
                    total_file_size -= PKCS5_OFFSET(prev_chunk)
                if use_openssl_only:
                    outfile.write(decryptor.finalize())
                outfile.truncate(total_file_size)
        return temp_output_file 
開發者ID:snowflakedb,項目名稱:snowflake-connector-python,代碼行數:63,代碼來源:encryption_util.py


注:本文中的Cryptodome.Cipher.AES.MODE_ECB屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。