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


Python AES.MODE_CFB属性代码示例

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


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

示例1: test_aes_128_cfb128

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def test_aes_128_cfb128(self):
        plaintext =     '6bc1bee22e409f96e93d7e117393172a' +\
                        'ae2d8a571e03ac9c9eb76fac45af8e51' +\
                        '30c81c46a35ce411e5fbc1191a0a52ef' +\
                        'f69f2445df4f9b17ad2b417be66c3710'
        ciphertext =    '3b3fd92eb72dad20333449f8e83cfb4a' +\
                        'c8a64537a0b3a93fcde3cdad9f1ce58b' +\
                        '26751f67a3cbb140b1808cf187a4f4df' +\
                        'c04b05357c5d1c0eeac4c66f9ff7f2e6'
        key =           '2b7e151628aed2a6abf7158809cf4f3c'
        iv =            '000102030405060708090a0b0c0d0e0f'

        key = unhexlify(key)
        iv = unhexlify(iv)
        plaintext = unhexlify(plaintext)
        ciphertext = unhexlify(ciphertext)

        cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128)
        self.assertEqual(cipher.encrypt(plaintext), ciphertext)
        cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128)
        self.assertEqual(cipher.decrypt(ciphertext), plaintext) 
开发者ID:bkerler,项目名称:android_universal,代码行数:23,代码来源:test_CFB.py

示例2: decrypt_private_key

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def decrypt_private_key(encrypted_private_key: bytes, password: str) -> str:
        '''
        Decrypt private key with the password.

        Args:
            encrypted_private_key (bytes): encrypted private key
            password (str): password to decrypt private key with

        Returns:
            str: decrypted private key
        '''
        encrypted_private_key = base64.b64decode(encrypted_private_key)
        iv = encrypted_private_key[:AES.block_size]
        cipher = AES.new(sha256(bytes(password.encode('utf-8'))).digest(), AES.MODE_CFB, iv)
        private_key = cipher.decrypt(encrypted_private_key[AES.block_size:])
        return str(private_key, 'ascii') 
开发者ID:Lamden,项目名称:clove,代码行数:18,代码来源:wallet.py

示例3: encrypt

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def encrypt(plaintext, key):
    """
    Encrypt the plaintext with AES method.

    Parameters:
        plaintext -- String to be encrypted.
        key       -- Key for encryption.
    """

    iv = Random.new().read(AES.block_size)
    cipher = AES.new(pad(key), AES.MODE_CFB, iv)
    # If user has entered non ascii password (Python2)
    # we have to encode it first
    if hasattr(str, 'decode'):
        plaintext = plaintext.encode('utf-8')
    encrypted = base64.b64encode(iv + cipher.encrypt(plaintext))

    return encrypted 
开发者ID:artikrh,项目名称:HackTheBox,代码行数:20,代码来源:crypto.py

示例4: decrypt

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def decrypt(ciphertext, key):
    """
    Decrypt the AES encrypted string.

    Parameters:
        ciphertext -- Encrypted string with AES method.
        key        -- key to decrypt the encrypted string.
    """

    global padding_string

    ciphertext = base64.b64decode(ciphertext)
    iv = ciphertext[:AES.block_size]
    cipher = AES.new(pad(key), AES.MODE_CFB, iv)
    decrypted = cipher.decrypt(ciphertext[AES.block_size:])

    return decrypted 
开发者ID:artikrh,项目名称:HackTheBox,代码行数:19,代码来源:crypto.py

示例5: encryptData

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def encryptData(self, encryptKey, privParameters, dataToEncrypt):
        if AES is None:
            raise error.StatusInformation(
                errorIndication=errind.encryptionError
                )
 
        snmpEngineBoots, snmpEngineTime, salt = privParameters

        # 3.3.1.1
        aesKey, iv, salt = self.__getEncryptionKey(
            encryptKey, snmpEngineBoots, snmpEngineTime
            )

        # 3.3.1.3
        aesObj = AES.new(aesKey, AES.MODE_CFB, iv, segment_size=128)

        # PyCrypto seems to require padding
        dataToEncrypt = dataToEncrypt + univ.OctetString((0,) * (16-len(dataToEncrypt)%16)).asOctets()

        ciphertext = aesObj.encrypt(dataToEncrypt)

        # 3.3.1.4
        return univ.OctetString(ciphertext), univ.OctetString(salt)
        
    # 3.2.4.2 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:27,代码来源:aes.py

示例6: decrypt_session_key

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def decrypt_session_key(db,kdfDeriveS,aes):
    masterKey=b''
    conn=ctx.sqlite_run_cmd(db,"select k,v from secconfig;")
    if (conn==-1):
        return masterKey
    rows=ctx.sqlite_get_data_size(conn)[0]
    encnames=['RSA_PRIV','HID','PRIVATE_KEY','MASTER_KEY','ECC_PRIV','ENC_TEST_KEY','DURESS_PWD','SERVER_SES_KEY']
    debase=['SERV_PUB_KEY','PUBLIC_KEY','ECC_PUB','ECDH_SERVPUB','AGENT_PIN']
    for i in range(0,rows):
        name=ctx.sqlite_get_data(conn,i,0)
        if (name in encnames):
                IV = b'0' * 16
                aes = AES.new(kdfDeriveS[0:32], AES.MODE_CFB, IV, segment_size=128)
                data = aes.decrypt(base64.b64decode(ctx.sqlite_get_data(conn,i,1)))
                if (name == 'MASTER_KEY'):
                    masterKey=data
        elif (name in debase):
            data=base64.b64decode(ctx.sqlite_get_data(conn,i,1))
    ctx.sqlite_cmd_close(conn)
    return masterKey 
开发者ID:bkerler,项目名称:MR,代码行数:22,代码来源:bb10_skyecc.py

示例7: test_aes_256_cfb128

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def test_aes_256_cfb128(self):
        plaintext =     '6bc1bee22e409f96e93d7e117393172a' +\
                        'ae2d8a571e03ac9c9eb76fac45af8e51' +\
                        '30c81c46a35ce411e5fbc1191a0a52ef' +\
                        'f69f2445df4f9b17ad2b417be66c3710'

        ciphertext =    'dc7e84bfda79164b7ecd8486985d3860' +\
                        '39ffed143b28b1c832113c6331e5407b' +\
                        'df10132415e54b92a13ed0a8267ae2f9' +\
                        '75a385741ab9cef82031623d55b1e471'
        key =           '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4'
        iv =            '000102030405060708090a0b0c0d0e0f'

        key = unhexlify(key)
        iv = unhexlify(iv)
        plaintext = unhexlify(plaintext)
        ciphertext = unhexlify(ciphertext)

        cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128)
        self.assertEqual(cipher.encrypt(plaintext), ciphertext)
        cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=128)
        self.assertEqual(cipher.decrypt(ciphertext), plaintext) 
开发者ID:vcheckzen,项目名称:FODI,代码行数:24,代码来源:test_CFB.py

示例8: get_cipher

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def get_cipher(self, key, iv):
            if len(key) > 32:
                raise ValueError('Key length cannot exceed 32 bytes.')
            key = key + ' ' * (32 - len(key))
            return AES.new(key, AES.MODE_CFB, iv) 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:7,代码来源:fields.py

示例9: init_crypto_nt6

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def init_crypto_nt6(self):
        self.iv = self.get_constant_object(
            'InitializationVector', 'String', length=16, term=None).v()

        aes_handle = self.get_constant_object(
            'hAesKey', target='Pointer',
            target_args=dict(target='_KIWI_BCRYPT_HANDLE_KEY'))

        self.aes_key = aes_handle.key.hardkey.data.v()

        des_handle = self.get_constant_object(
            'h3DesKey', target='Pointer',
            target_args=dict(target='_KIWI_BCRYPT_HANDLE_KEY'))

        self.des_key = des_handle.key.hardkey.data.v()

        try:
            cipher = AES.new(self.aes_key, AES.MODE_CFB, self.iv)
            cipher = DES3.new(self.des_key, DES3.MODE_CBC, self.iv[:8])
            cipher = None
            decryption_enabled = True
        except ValueError as e_ve:
            decryption_enabled = False
            logging.warning('init_crypto_nt6 exception {}'.format(e_ve))
        finally:
            return decryption_enabled 
开发者ID:google,项目名称:rekall,代码行数:28,代码来源:mimikatz.py

示例10: decrypt_nt6

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def decrypt_nt6(self, encrypted):
        if not self.decryption_enabled:
            return obj.NoneObject()

        cipher = None
        if self.iv:
            if len(encrypted) % 8:
                cipher = AES.new(self.aes_key, AES.MODE_CFB, self.iv)
            else:
                if self.des_key:
                    cipher = DES3.new(self.des_key, DES3.MODE_CBC, self.iv[:8])
        if cipher and encrypted:
            return cipher.decrypt(encrypted)
        return obj.NoneObject() 
开发者ID:google,项目名称:rekall,代码行数:16,代码来源:mimikatz.py

示例11: ComputeNetlogonCredentialAES

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def ComputeNetlogonCredentialAES(inputData, Sk):
    IV='\x00'*16
    Crypt1 = AES.new(Sk, AES.MODE_CFB, IV)
    return Crypt1.encrypt(inputData)

# Section 3.1.4.3.1 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:8,代码来源:nrpc.py

示例12: encryptSequenceNumberAES

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def encryptSequenceNumberAES(sequenceNum, checkSum, sessionKey):
    # [MS-NRPC] Section 3.3.4.2.1, point 9
    IV = checkSum[:8] + checkSum[:8]
    Cipher = AES.new(sessionKey, AES.MODE_CFB, IV)
    return Cipher.encrypt(sequenceNum) 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:7,代码来源:nrpc.py

示例13: decryptSequenceNumberAES

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def decryptSequenceNumberAES(sequenceNum, checkSum, sessionKey):
    # [MS-NRPC] Section 3.3.4.2.1, point 9
    IV = checkSum[:8] + checkSum[:8]
    Cipher = AES.new(sessionKey, AES.MODE_CFB, IV)
    return Cipher.decrypt(sequenceNum) 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:7,代码来源:nrpc.py

示例14: SEAL

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def SEAL(data, confounder, sequenceNum, key, aes = False):
    signature = SIGN(data, confounder, sequenceNum, key, aes)
    sequenceNum = deriveSequenceNumber(sequenceNum)
    XorKey = []
    for i in key:
       XorKey.append(chr(ord(i) ^ 0xf0))

    XorKey = ''.join(XorKey)
    if aes is False:
        hm = hmac.new(XorKey)
        hm.update('\x00'*4)
        hm2 = hmac.new(hm.digest())
        hm2.update(sequenceNum)
        encryptionKey = hm2.digest()

        cipher = ARC4.new(encryptionKey)
        cfounder = cipher.encrypt(confounder)
        cipher = ARC4.new(encryptionKey)
        encrypted = cipher.encrypt(data)

        signature['Confounder'] = cfounder

        return encrypted, signature
    else:
        IV = sequenceNum + sequenceNum
        cipher = AES.new(XorKey, AES.MODE_CFB, IV)
        cfounder = cipher.encrypt(confounder)
        encrypted = cipher.encrypt(data)

        signature['Confounder'] = cfounder

        return encrypted, signature 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:34,代码来源:nrpc.py

示例15: UNSEAL

# 需要导入模块: from Crypto.Cipher import AES [as 别名]
# 或者: from Crypto.Cipher.AES import MODE_CFB [as 别名]
def UNSEAL(data, auth_data, key, aes = False):
    auth_data = NL_AUTH_SIGNATURE(auth_data)
    XorKey = []
    for i in key:
       XorKey.append(chr(ord(i) ^ 0xf0))

    XorKey = ''.join(XorKey)
    if aes is False:
        sequenceNum = decryptSequenceNumberRC4(auth_data['SequenceNumber'], auth_data['Checksum'],  key)
        hm = hmac.new(XorKey)
        hm.update('\x00'*4)
        hm2 = hmac.new(hm.digest())
        hm2.update(sequenceNum)
        encryptionKey = hm2.digest()

        cipher = ARC4.new(encryptionKey)
        cfounder = cipher.encrypt(auth_data['Confounder'])
        cipher = ARC4.new(encryptionKey)
        plain = cipher.encrypt(data)

        return plain, cfounder
    else:
        sequenceNum = decryptSequenceNumberAES(auth_data['SequenceNumber'], auth_data['Checksum'],  key)
        IV = sequenceNum + sequenceNum
        cipher = AES.new(XorKey, AES.MODE_CFB, IV)
        cfounder = cipher.decrypt(auth_data['Confounder'])
        plain = cipher.decrypt(data)
        return plain, cfounder 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:30,代码来源:nrpc.py


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