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


Python algorithms.ARC4属性代码示例

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


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

示例1: verifypw

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def verifypw(password, salt, encryptedVerifier, encryptedVerifierHash):
        r'''
        Return True if the given password is valid.

            >>> password = 'password1'
            >>> salt = b'\xe8w,\x1d\x91\xc5j7\x96Ga\xb2\x80\x182\x17'
            >>> encryptedVerifier = b'\xc9\xe9\x97\xd4T\x97=1\x0b\xb1\xbap\x14&\x83~'
            >>> encryptedVerifierHash = b'\xb1\xde\x17\x8f\x07\xe9\x89\xc4M\xae^L\xf9j\xc4\x07'
            >>> DocumentRC4.verifypw(password, salt, encryptedVerifier, encryptedVerifierHash)
            True
        '''
        # https://msdn.microsoft.com/en-us/library/dd952648(v=office.12).aspx
        block = 0
        key = _makekey(password, salt, block)
        cipher = Cipher(algorithms.ARC4(key), mode=None, backend=default_backend())
        decryptor = cipher.decryptor()
        verifier = decryptor.update(encryptedVerifier)
        verfiferHash = decryptor.update(encryptedVerifierHash)
        hash = md5(verifier).digest()
        logging.debug([verfiferHash, hash])
        return hash == verfiferHash 
开发者ID:nolze,项目名称:msoffcrypto-tool,代码行数:23,代码来源:rc4.py

示例2: decrypt

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def decrypt(password, salt, ibuf, blocksize=0x200):
        r'''
        Return decrypted data.
        '''
        obuf = io.BytesIO()

        block = 0
        key = _makekey(password, salt, block)

        for c, buf in enumerate(iter(functools.partial(ibuf.read, blocksize), b'')):
            cipher = Cipher(algorithms.ARC4(key), mode=None, backend=default_backend())
            decryptor = cipher.decryptor()

            dec = decryptor.update(buf) + decryptor.finalize()
            obuf.write(dec)

            # From wvDecrypt:
            # at this stage we need to rekey the rc4 algorithm
            # Dieter Spaar <spaar@mirider.augusta.de> figured out
            # this rekeying, big kudos to him
            block += 1
            key = _makekey(password, salt, block)

        obuf.seek(0)
        return obuf 
开发者ID:nolze,项目名称:msoffcrypto-tool,代码行数:27,代码来源:rc4.py

示例3: decrypt

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def decrypt(password, salt, keySize, ibuf, blocksize=0x200, block=0):
        r'''
        Return decrypted data.
        '''
        obuf = io.BytesIO()

        key = _makekey(password, salt, keySize, block)

        for c, buf in enumerate(iter(functools.partial(ibuf.read, blocksize), b'')):
            cipher = Cipher(algorithms.ARC4(key), mode=None, backend=default_backend())
            decryptor = cipher.decryptor()

            dec = decryptor.update(buf) + decryptor.finalize()
            obuf.write(dec)

            # From wvDecrypt:
            # at this stage we need to rekey the rc4 algorithm
            # Dieter Spaar <spaar@mirider.augusta.de> figured out
            # this rekeying, big kudos to him
            block += 1
            key = _makekey(password, salt, keySize, block)

        obuf.seek(0)
        return obuf 
开发者ID:nolze,项目名称:msoffcrypto-tool,代码行数:26,代码来源:rc4_cryptoapi.py

示例4: encrypt

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def encrypt(self, p, pay, key=None):
        if key is None:
            key = conf.wepkey
        if key:
            if self.icv is None:
                pay += struct.pack("<I", crc32(pay) & 0xffffffff)
                icv = b""
            else:
                icv = p[4:8]
            e = Cipher(
                algorithms.ARC4(self.iv + key.encode("utf8")),
                None,
                default_backend(),
            ).encryptor()
            return p[:4] + e.update(pay) + e.finalize() + icv
        else:
            warning("No WEP key set (conf.wepkey).. strange results expected..")  # noqa: E501
            return b"" 
开发者ID:secdev,项目名称:scapy,代码行数:20,代码来源:dot11.py

示例5: __init__

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def __init__(self, key=None, **kwargs):
    """Initializes a decrypter.

    Args:
      key (Optional[bytes]): key.
      kwargs (dict): keyword arguments depending on the decrypter.

    Raises:
      ValueError: when key is not set.
    """
    if not key:
      raise ValueError('Missing key.')

    algorithm = algorithms.ARC4(key)

    backend = backends.default_backend()
    cipher = ciphers.Cipher(algorithm, mode=None, backend=backend)

    super(RC4Decrypter, self).__init__(**kwargs)
    self._cipher_context = cipher.decryptor()

  # pylint: disable=unused-argument 
开发者ID:log2timeline,项目名称:dfvfs,代码行数:24,代码来源:rc4_decrypter.py

示例6: verifypw

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def verifypw(password, salt, keySize, encryptedVerifier, encryptedVerifierHash, algId=0x00006801, block=0):
        r'''
        Return True if the given password is valid.
        '''
        # TODO: For consistency with others, rename method to verify_password or the like
        # https://msdn.microsoft.com/en-us/library/dd953617(v=office.12).aspx
        key = _makekey(password, salt, keySize, block)
        cipher = Cipher(algorithms.ARC4(key), mode=None, backend=default_backend())
        decryptor = cipher.decryptor()
        verifier = decryptor.update(encryptedVerifier)
        verfiferHash = decryptor.update(encryptedVerifierHash)
        hash = sha1(verifier).digest()
        logging.debug([verfiferHash, hash])
        return hash == verfiferHash 
开发者ID:nolze,项目名称:msoffcrypto-tool,代码行数:16,代码来源:rc4_cryptoapi.py

示例7: setup_cipher

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def setup_cipher(self):
		algorithm = algorithms.ARC4(self.key)
		self._cipher = Cipher(algorithm, mode=None, backend=default_backend())
		self.encryptor = self._cipher.encryptor()
		self.decryptor = self._cipher.decryptor() 
开发者ID:skelsec,项目名称:minikerberos,代码行数:7,代码来源:RC4.py

示例8: __init__

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def __init__(self, key):
        algo = algorithms.ARC4(key)
        cipher = Cipher(algo, mode=None, backend=default_backend())
        self._encryptor = cipher.encryptor() 
开发者ID:jborean93,项目名称:ntlm-auth,代码行数:6,代码来源:rc4.py

示例9: ARC4_encrypt

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def ARC4_encrypt(key, data, skip=0):
    """Encrypt data @data with key @key, skipping @skip first bytes of the
    keystream"""

    algorithm = algorithms.ARC4(key)
    cipher = Cipher(algorithm, mode=None, backend=default_backend())
    encryptor = cipher.encryptor()
    if skip:
        encryptor.update(b"\x00" * skip)
    return encryptor.update(data) 
开发者ID:secdev,项目名称:scapy,代码行数:12,代码来源:crypto.py

示例10: decrypt

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def decrypt(self, key=None):
        if key is None:
            key = conf.wepkey
        if key and conf.crypto_valid:
            d = Cipher(
                algorithms.ARC4(self.iv + key.encode("utf8")),
                None,
                default_backend(),
            ).decryptor()
            self.add_payload(LLC(d.update(self.wepdata) + d.finalize())) 
开发者ID:secdev,项目名称:scapy,代码行数:12,代码来源:dot11.py

示例11: __init__

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def __init__(self, key):
            if isinstance(key, str):
                key = key.encode('utf-8')
            cipher = Cipher(algorithms.ARC4(key), mode=None, backend=default_backend())
            self.encrypter = cipher.encryptor() 
开发者ID:candlepin,项目名称:virt-who,代码行数:7,代码来源:ntlm.py

示例12: _DecryptARC4

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def _DecryptARC4(self, key, data):
    """Decrypts ARC4 encrypted data.

    Args:
      key (str): key used to decrypt the data.
      data (bytes): data to decrypt.

    Returns:
      bytes: decrypted data.
    """
    algorithm = algorithms.ARC4(key)
    backend = backends.default_backend()
    cipher = ciphers.Cipher(algorithm, mode=None, backend=backend)
    cipher_context = cipher.decryptor()
    return cipher_context.update(data) 
开发者ID:libyal,项目名称:winreg-kb,代码行数:17,代码来源:cached_credentials.py

示例13: get_encryptor

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def get_encryptor(algoname, key, iv=None, mode='ecb', padd='pkcs7'):
    backend  = default_backend()
    if algoname == 'ChaCha20':
        algoer = algorithms.ChaCha20(key, iv)
        cipher = Cipher(algoer, None, backend=backend)
    elif algoname == 'ARC4':
        algoer = algorithms.ARC4(key)
        cipher = Cipher(algoer, None, backend=backend)
    else:
        algoer = algos[algoname](key)
        if mode == 'ecb': mode = modes.ECB()
        if mode == 'cfb': mode = modes.CFB(iv)
        if mode == 'ofb': mode = modes.OFB(iv)
        if mode == 'cbc': mode = modes.CBC(iv)
        if mode == 'ctr': mode = modes.CTR(iv)
        cipher = Cipher(algoer, mode, backend=backend)

    def enc(bitstring):
        if algoname not in ['ARC4', 'ChaCha20']:
            if padd.upper() == 'PKCS7':
                padder    = padding.PKCS7(algoer.block_size).padder()
                bitstring = padder.update(bitstring) + padder.finalize()
            elif padd.upper() == 'ANSIX923':
                padder    = padding.ANSIX923(algoer.block_size).padder()
                bitstring = padder.update(bitstring) + padder.finalize()
        encryptor = cipher.encryptor()
        return encryptor.update(bitstring) + encryptor.finalize()

    def dec(bitstring):
        decryptor = cipher.decryptor()
        ddata = decryptor.update(bitstring) + decryptor.finalize()
        if algoname not in ['ARC4', 'ChaCha20']:
            if padd.upper() == 'PKCS7':
                unpadder  = padding.PKCS7(algoer.block_size).unpadder()
                ddata = unpadder.update(ddata) + unpadder.finalize()
            elif padd.upper() == 'ANSIX923':
                unpadder  = padding.ANSIX923(algoer.block_size).unpadder()
                ddata = unpadder.update(ddata) + unpadder.finalize()
        return ddata
    class f:pass
    f.encrypt = enc
    f.decrypt = dec
    return f 
开发者ID:cilame,项目名称:vrequest,代码行数:45,代码来源:pymultialgo.py

示例14: test_bad_cryptography_module_attribute_usage

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def test_bad_cryptography_module_attribute_usage(self):
        python_node = self.get_ast_node(
            """
            import cryptography.hazmat.primitives.hashes
            import cryptography.hazmat.primitives.ciphers.modes
            import cryptography.hazmat.primitives.ciphers.algorithms
            import cryptography.hazmat.primitives.asymmetric.padding

            cryptography.hazmat.primitives.hashes.MD5
            cryptography.hazmat.primitives.hashes.SHA1
            cryptography.hazmat.primitives.ciphers.modes.ECB
            cryptography.hazmat.primitives.ciphers.algorithms.Blowfish
            cryptography.hazmat.primitives.ciphers.algorithms.ARC4
            cryptography.hazmat.primitives.ciphers.algorithms.IDEA
            cryptography.hazmat.primitives.asymmetric.padding.PKCS1v15
            """
        )

        linter = dlint.linters.BadCryptographyModuleAttributeUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=7,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=8,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=9,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=10,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=11,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=12,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=13,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
        ]

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:63,代码来源:test_bad_cryptography_module_attribute_use.py

示例15: test_bad_cryptography_module_attribute_usage_from_import

# 需要导入模块: from cryptography.hazmat.primitives.ciphers import algorithms [as 别名]
# 或者: from cryptography.hazmat.primitives.ciphers.algorithms import ARC4 [as 别名]
def test_bad_cryptography_module_attribute_usage_from_import(self):
        python_node = self.get_ast_node(
            """
            from cryptography.hazmat.primitives import hashes
            from cryptography.hazmat.primitives.ciphers import modes
            from cryptography.hazmat.primitives.ciphers import algorithms
            from cryptography.hazmat.primitives.asymmetric import padding

            hashes.MD5
            hashes.SHA1
            modes.ECB
            algorithms.Blowfish
            algorithms.ARC4
            algorithms.IDEA
            padding.PKCS1v15
            """
        )

        linter = dlint.linters.BadCryptographyModuleAttributeUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=7,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=8,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=9,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=10,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=11,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=12,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=13,
                col_offset=0,
                message=dlint.linters.BadCryptographyModuleAttributeUseLinter._error_tmpl
            ),
        ]

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:63,代码来源:test_bad_cryptography_module_attribute_use.py


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