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


Python pyaes.Decrypter方法代码示例

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


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

示例1: _decrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import Decrypter [as 别名]
def _decrypt(self, msg, key, iv):
		from binascii import unhexlify, hexlify
		import pyaes

		msg = unhexlify(msg)
		key = unhexlify(key)
		iv = unhexlify(iv)

		if len(iv) != 16:
			return False

		decrypter = pyaes.Decrypter(pyaes.AESModeOfOperationCBC(key, iv))
		plain_text = decrypter.feed(msg)
		plain_text += decrypter.feed()
		f = hexlify(plain_text)
		return f 
开发者ID:a4k-openproject,项目名称:script.module.openscrapers,代码行数:18,代码来源:client.py

示例2: decrypt_data

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import Decrypter [as 别名]
def decrypt_data(key, data):
    decrypter = Decrypter(AESModeOfOperationCBC(key, iv=data[:16]))
    plain = decrypter.feed(data[16:])
    plain += decrypter.feed()
    return plain 
开发者ID:JoinMarket-Org,项目名称:joinmarket-clientserver,代码行数:7,代码来源:convert_old_wallet.py

示例3: decrypt_py

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import Decrypter [as 别名]
def decrypt_py(cipher_text, key):
    if cipher_text:
        try:
            scraper_key = hashlib.sha256(key).digest()
            IV = '\0' * 16
            decrypter = pyaes.Decrypter(pyaes.AESModeOfOperationCBC(scraper_key, IV))
            plain_text = decrypter.feed(cipher_text)
            plain_text += decrypter.feed()
            if 'import' not in plain_text:
                plain_text = ''
        except Exception as e:
            log_utils.log_warning('Exception during Py Decrypt: %s' % (e))
            plain_text = ''
    else:
        plain_text = ''

    return plain_text 
开发者ID:mrknow,项目名称:filmkodi,代码行数:19,代码来源:common.py

示例4: _decrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import Decrypter [as 别名]
def _decrypt(self, value, encrypted_value):
        """Decrypt encoded cookies
        """

        if sys.platform == 'win32':
            try:
                return self._decrypt_windows_chrome(value, encrypted_value)

            # Fix for change in Chrome 80
            except RuntimeError:  # Failed to decrypt the cipher text with DPAPI
                if not self.key:
                    raise RuntimeError(
                        'Failed to decrypt the cipher text with DPAPI and no AES key.')
                # Encrypted cookies should be prefixed with 'v10' according to the
                # Chromium code. Strip it off.
                encrypted_value = encrypted_value[3:]
                nonce, tag = encrypted_value[:12], encrypted_value[-16:]
                aes = AES.new(self.key, AES.MODE_GCM, nonce=nonce)

                data = aes.decrypt_and_verify(encrypted_value[12:-16], tag)
                return data.decode()

        if value or (encrypted_value[:3] not in [b'v11', b'v10']):
            return value

        # Encrypted cookies should be prefixed with 'v10' according to the
        # Chromium code. Strip it off.
        encrypted_value = encrypted_value[3:]
        encrypted_value_half_len = int(len(encrypted_value) / 2)

        cipher = pyaes.Decrypter(
            pyaes.AESModeOfOperationCBC(self.key, self.iv))
        decrypted = cipher.feed(encrypted_value[:encrypted_value_half_len])
        decrypted += cipher.feed(encrypted_value[encrypted_value_half_len:])
        decrypted += cipher.feed()
        return decrypted.decode("utf-8") 
开发者ID:borisbabic,项目名称:browser_cookie3,代码行数:38,代码来源:__init__.py

示例5: decrypt_aes_cbc

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import Decrypter [as 别名]
def decrypt_aes_cbc(key, ciphertext, iv=None):
        """Return AES CBC decrypted string.

        Args:
            key (bytes): The encryption key.
            ciphertext (bytes): The ciphertext to decrypt.
            iv (bytes, optional): The CBC initial vector.

        Returns:
            bytes: The encoded string.
        """
        iv = iv or b'\0' * 16

        # ensure key is bytes
        if isinstance(key, str):
            key = key.encode()

        # ensure plaintext is bytes
        if isinstance(ciphertext, str):
            ciphertext = ciphertext.encode()

        # ensure iv is bytes
        if isinstance(iv, str):
            iv = iv.encode()

        aes_cbc_decrypt = pyaes.Decrypter(pyaes.AESModeOfOperationCBC(key, iv=iv))
        decrypted = aes_cbc_decrypt.feed(ciphertext)
        decrypted += aes_cbc_decrypt.feed()
        return decrypted 
开发者ID:ThreatConnect-Inc,项目名称:tcex,代码行数:31,代码来源:utils.py

示例6: use_slow_bundled_cryptography_module

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import Decrypter [as 别名]
def use_slow_bundled_cryptography_module():
    import pyaes

    msg = "To make the program a *lot* faster, please install cryptography module: "
    msg += "pip install cryptography\n"
    print(msg, flush=True, file=sys.stderr)

    class BundledEncryptorAdapter:
        __slots__ = ('mode', )

        def __init__(self, mode):
            self.mode = mode

        def encrypt(self, data):
            encrypter = pyaes.Encrypter(self.mode, pyaes.PADDING_NONE)
            return encrypter.feed(data) + encrypter.feed()

        def decrypt(self, data):
            decrypter = pyaes.Decrypter(self.mode, pyaes.PADDING_NONE)
            return decrypter.feed(data) + decrypter.feed()

    def create_aes_ctr(key, iv):
        ctr = pyaes.Counter(iv)
        return pyaes.AESModeOfOperationCTR(key, ctr)

    def create_aes_cbc(key, iv):
        mode = pyaes.AESModeOfOperationCBC(key, iv)
        return BundledEncryptorAdapter(mode)
    return create_aes_ctr, create_aes_cbc 
开发者ID:alexbers,项目名称:mtprotoproxy,代码行数:31,代码来源:mtprotoproxy.py

示例7: TestIssue15

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import Decrypter [as 别名]
def TestIssue15():
    print('Issue #15')

    key = b"abcdefghijklmnop"
    iv = b"0123456789012345"
    encrypter = pyaes.Encrypter(pyaes.AESModeOfOperationCBC(key, iv))

    plaintext = b"Hello World!!!!!"

    ciphertext = to_bufferable('')

    ciphertext += encrypter.feed(plaintext)
    ciphertext += encrypter.feed('')
    ciphertext += encrypter.feed(plaintext)
    ciphertext += encrypter.feed(None)
    expected = b'(Ob\xe5\xae"\xdc\xb0\x84\xc5\x04\x04GQ\xd8.\x0e4\xd2b\xc1\x15\xe5\x11M\xfc\x9a\xd2\xd5\xc8xP\x00[\xd57\x92\x01\xbb\xc42\x18\xbc\xbf\x1ay\x19P'

    decrypter = pyaes.Decrypter(pyaes.AESModeOfOperationCBC(key, iv))

    output = to_bufferable('')

    output += decrypter.feed('')
    output += decrypter.feed(ciphertext)
    output += decrypter.feed('')
    output += decrypter.feed(None)

    print("  passed=%(passed)s" % dict(passed = (ciphertext == expected and output == (plaintext + plaintext)))) 
开发者ID:ricmoo,项目名称:pyaes,代码行数:29,代码来源:test-blockfeeder.py

示例8: aes_decrypt_with_iv

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import Decrypter [as 别名]
def aes_decrypt_with_iv(key, iv, data):
    aes_cbc = pyaes.AESModeOfOperationCBC(key, iv=iv)
    aes = pyaes.Decrypter(aes_cbc)
    s = aes.feed(data) + aes.feed()  # empty aes.feed() strips pkcs padding
    return s 
开发者ID:bitcoin-core,项目名称:HWI,代码行数:7,代码来源:digitalbitbox.py

示例9: _decrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import Decrypter [as 别名]
def _decrypt(self, data, iv):
        decrypter = pyaes.Decrypter(
                pyaes.AESModeOfOperationCBC(self._hash.hash, iv=native(iv)))
        try:
            dec_data = decrypter.feed(data)
            dec_data += decrypter.feed()
        except ValueError:
            # in most "wrong password" cases the pkcs7 padding will be wrong
            raise StoragePasswordError("Wrong password.")

        if not dec_data.startswith(self.MAGIC_DETECT_ENC):
            raise StoragePasswordError("Wrong password.")
        return dec_data[len(self.MAGIC_DETECT_ENC):] 
开发者ID:JoinMarket-Org,项目名称:joinmarket-clientserver,代码行数:15,代码来源:storage.py

示例10: _decrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import Decrypter [as 别名]
def _decrypt(self, msg, key, iv):
        from binascii import unhexlify, hexlify
        import pyaes
        msg = unhexlify(msg)
        key = unhexlify(key)
        iv = unhexlify(iv)
        if len(iv) != 16: return False
        decrypter = pyaes.Decrypter(pyaes.AESModeOfOperationCBC(key, iv))
        plain_text = decrypter.feed(msg)
        plain_text += decrypter.feed()
        f = hexlify(plain_text)
        return f 
开发者ID:mrknow,项目名称:filmkodi,代码行数:14,代码来源:client.py

示例11: aes_cbc_decrypt

# 需要导入模块: import pyaes [as 别名]
# 或者: from pyaes import Decrypter [as 别名]
def aes_cbc_decrypt(key: bytes, iv: bytes, encrypted_data: bytes) -> str:
    decrypter = Decrypter(AESModeOfOperationCBC(key, iv))
    decrypted = decrypter.feed(encrypted_data) + decrypter.feed()
    return decrypted.decode("utf-8") 
开发者ID:mkb79,项目名称:Audible,代码行数:6,代码来源:aescipher.py


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