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


Python hashes.MD5属性代码示例

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


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

示例1: _legacy_pkcs1_v1_5_encode_md5_sha1

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def _legacy_pkcs1_v1_5_encode_md5_sha1(M, emLen):
    """
    Legacy method for PKCS1 v1.5 encoding with MD5-SHA1 hash.
    """
    M = bytes_encode(M)
    md5_hash = hashes.Hash(_get_hash("md5"), backend=default_backend())
    md5_hash.update(M)
    sha1_hash = hashes.Hash(_get_hash("sha1"), backend=default_backend())
    sha1_hash.update(M)
    H = md5_hash.finalize() + sha1_hash.finalize()
    if emLen < 36 + 11:
        warning("pkcs_emsa_pkcs1_v1_5_encode: "
                "intended encoded message length too short")
        return None
    PS = b'\xff' * (emLen - 36 - 3)
    return b'\x00' + b'\x01' + PS + b'\x00' + H


#####################################################################
# Hash and padding helpers
##################################################################### 
开发者ID:secdev,项目名称:scapy,代码行数:23,代码来源:pkcs1.py

示例2: test_sign_non_RSA

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def test_sign_non_RSA(self):
        """
        Test that an InvalidField exception is raised when sign is
        called with a crypto algorithm other than RSA.
        """
        engine = crypto.CryptographyEngine()

        args = (
            None,
            enums.CryptographicAlgorithm.TRIPLE_DES,
            enums.HashingAlgorithm.MD5,
            None,
            None,
            None
        )
        self.assertRaisesRegex(
            exceptions.InvalidField,
            'For signing, an RSA key must be used.',
            engine.sign,
            *args
        ) 
开发者ID:OpenKMIP,项目名称:PyKMIP,代码行数:23,代码来源:test_engine.py

示例3: test_sign_invalid_padding

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def test_sign_invalid_padding(self):
        """
        Test that an InvalidField exception is raised when sign is
        called with an unsupported padding algorithm.
        """
        engine = crypto.CryptographyEngine()

        args = (
            None,
            enums.CryptographicAlgorithm.RSA,
            enums.HashingAlgorithm.MD5,
            enums.PaddingMethod.OAEP,
            DER_RSA_KEY,
            None
        )
        self.assertRaisesRegex(
            exceptions.InvalidField,
            "Padding method 'PaddingMethod.OAEP' is not a supported"
            " signature padding method.",
            engine.sign,
            *args
        ) 
开发者ID:OpenKMIP,项目名称:PyKMIP,代码行数:24,代码来源:test_engine.py

示例4: test_sign_no_padding

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def test_sign_no_padding(self):
        """
        Test that an InvalidField exception is raised when sign is
        called without a padding algorithm.
        """
        engine = crypto.CryptographyEngine()

        args = (
            None,
            enums.CryptographicAlgorithm.RSA,
            enums.HashingAlgorithm.MD5,
            None,
            DER_RSA_KEY,
            None
        )
        self.assertRaisesRegex(
            exceptions.InvalidField,
            'For signing, a padding method must be specified.',
            engine.sign,
            *args
        ) 
开发者ID:OpenKMIP,项目名称:PyKMIP,代码行数:23,代码来源:test_engine.py

示例5: test_sign_invalid_key_bytes

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def test_sign_invalid_key_bytes(self):
        """
        Test that an InvalidField exception is raised when
        sign is called with invalid key bytes.
        """
        engine = crypto.CryptographyEngine()

        args = (
            None,
            enums.CryptographicAlgorithm.RSA,
            enums.HashingAlgorithm.MD5,
            enums.PaddingMethod.PKCS1v15,
            'thisisnotavalidkey',
            None
        )

        self.assertRaisesRegex(
            exceptions.InvalidField,
            'Unable to deserialize key '
            'bytes, unknown format.',
            engine.sign,
            *args
        ) 
开发者ID:OpenKMIP,项目名称:PyKMIP,代码行数:25,代码来源:test_engine.py

示例6: __init__

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def __init__(self, id="", cert_path="", key_path="", expiry=None,
                 keytype="", keylength=0, sha1="", md5=""):
        """
        Initialize the certificate authority object.

        :param str id: Authority (and domain) name
        :param str cert_path: Path to the certificate file on disk
        :param str key_path: Path to the certificate's key file on disk
        :param str expiry: ISO-8601 timestamp of certificate expiry
        :param str keytype: Key type (e.g. RSA or DSA)
        :param int keylength: Key bitlength (e.g. 2048, 4096, etc)
        :param str sha1: SHA-1 hash
        :param str md5: MD5 hash
        """
        self.id = id
        self.cert_path = cert_path
        self.key_path = key_path
        self.expiry = expiry
        self.keytype = keytype
        self.keylength = keylength
        self.sha1 = sha1
        self.md5 = md5 
开发者ID:arkOScloud,项目名称:core,代码行数:24,代码来源:certificates.py

示例7: _scan_a_cert

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def _scan_a_cert(id, cert_path, key_path, assigns, is_acme=False):
    with open(cert_path, "rb") as f:
        crt = x509.load_pem_x509_certificate(f.read(), default_backend())
    with open(key_path, "rb") as f:
        key = serialization.load_pem_private_key(
            f.read(),
            password=None,
            backend=default_backend()
        )
    sha1 = binascii.hexlify(crt.fingerprint(hashes.SHA1())).decode()
    md5 = binascii.hexlify(crt.fingerprint(hashes.MD5())).decode()
    sha1 = ":".join([sha1[i:i+2].upper() for i in range(0, len(sha1), 2)])
    md5 = ":".join([md5[i:i+2].upper() for i in range(0, len(md5), 2)])
    kt = "RSA" if isinstance(key.public_key(), rsa.RSAPublicKey) else "DSA"
    common_name = crt.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
    return Certificate(
        id=id, cert_path=cert_path, key_path=key_path, keytype=kt,
        keylength=key.key_size, domain=common_name[0].value,
        assigns=assigns.get(id, []), expiry=crt.not_valid_after, sha1=sha1,
        md5=md5, is_acme=is_acme) 
开发者ID:arkOScloud,项目名称:core,代码行数:22,代码来源:certificates.py

示例8: test_handle_symmetric_padding_undo

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def test_handle_symmetric_padding_undo(symmetric_padding_parameters):
    """
    Test that data of various lengths can be unpadded correctly using
    different padding schemes.
    """
    engine = crypto.CryptographyEngine()

    result = engine._handle_symmetric_padding(
        symmetric_padding_parameters.get('algorithm'),
        symmetric_padding_parameters.get('padded_text'),
        symmetric_padding_parameters.get('padding_method'),
        undo_padding=True
    )

    assert result == symmetric_padding_parameters.get('plain_text')


# PBKDF2 test vectors were obtained from IETF RFC 6070:
#
# https://www.ietf.org/rfc/rfc6070.txt
#
# HMAC test vectors were obtained from IETF RFC 5869:
#
# https://tools.ietf.org/html/rfc5869
#
# HASH test vectors for SHA1/SHA224/SHA256/SHA384/SHA512
# were obtained from the NIST CAVP test suite. Test vectors for MD5 were
# obtained from NIST NSRL:
#
# http://csrc.nist.gov/groups/STM/cavp/documents/shs/shabytetestvectors.zip
# https://www.nsrl.nist.gov/testdata/
#
# NIST 800-108 Counter Mode test vectors were obtained from the NIST CAVP
# test suite:
#
# http://csrc.nist.gov/groups/STM/cavp/documents/KBKDF800-108/kbkdfvs.pdf
# http://csrc.nist.gov/groups/STM/cavp/documents/KBKDF800-108/CounterMode.zip 
开发者ID:OpenKMIP,项目名称:PyKMIP,代码行数:39,代码来源:test_engine.py

示例9: test_overwrite

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def test_overwrite(self):
        idp = self.get_idp(full_name=self.get_idp_full_name(self.ca), only_contains_user_certs=True)
        response = self.client.get(reverse('advanced', kwargs={'serial': self.ca.serial}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'text/plain')
        self.assertCRL(response.content, expires=321, idp=idp, algorithm=hashes.MD5()) 
开发者ID:mathiasertl,项目名称:django-ca,代码行数:8,代码来源:tests_views.py

示例10: test_basic

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def test_basic(self):
        ns = self.parser.parse_args(['--algo=SHA256'])
        self.assertIsInstance(ns.algo, hashes.SHA256)

        ns = self.parser.parse_args(['--algo=MD5'])
        self.assertIsInstance(ns.algo, hashes.MD5)

        ns = self.parser.parse_args(['--algo=SHA512'])
        self.assertIsInstance(ns.algo, hashes.SHA512) 
开发者ID:mathiasertl,项目名称:django-ca,代码行数:11,代码来源:tests_management_base.py

示例11: scan_authorities

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def scan_authorities():
    """
    Search proper directory for certificates, load them and store metadata.

    :return: list of CertificateAuthority objects
    :rtype: list
    """
    logger.debug("Crts", "Scanning for certificate authorities")
    storage.certificate_authorities.clear()
    ca_cert_dir = config.get("certificates", "ca_cert_dir")
    ca_key_dir = config.get("certificates", "ca_key_dir")
    if not os.path.exists(ca_cert_dir):
        os.makedirs(ca_cert_dir)
    if not os.path.exists(ca_key_dir):
        os.makedirs(ca_key_dir)
    for x in glob.glob(os.path.join(ca_cert_dir, "*.pem")):
        id = os.path.splitext(os.path.split(x)[1])[0]
        with open(x, "rb") as f:
            cert = x509.load_pem_x509_certificate(f.read(), default_backend())
        key_path = os.path.join(ca_key_dir, "{0}.key".format(id))
        with open(key_path, "rb") as f:
            with open(key_path, "rb") as f:
                key = serialization.load_pem_private_key(
                    f.read(),
                    password=None,
                    backend=default_backend()
                )
        sha1 = binascii.hexlify(cert.fingerprint(hashes.SHA1())).decode()
        md5 = binascii.hexlify(cert.fingerprint(hashes.MD5())).decode()
        kt = "RSA" if isinstance(key.public_key(), rsa.RSAPublicKey) else "DSA"
        ca = CertificateAuthority(id, x, key_path, cert.not_valid_after,
                                  kt, key.key_size, sha1, md5)
        storage.certificate_authorities[id] = ca
    return storage.certificate_authorities 
开发者ID:arkOScloud,项目名称:core,代码行数:36,代码来源:certificates.py

示例12: _GetLSAKey

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def _GetLSAKey(self, registry, boot_key):
    """Retrieves the LSA key.

    Args:
      registry (dfwinreg.WinRegistry): Windows Registry.
      boot_key (bytes): boot key.

    Returns:
      bytes: LSA key or None if not found.
    """
    policy_encryption_key = registry.GetKeyByPath(
        self._POLICY_ENCRYPTION_KEY_PATH)
    if not policy_encryption_key:
      return None

    policy_encryption_value = policy_encryption_key.GetValueByName('')
    if not policy_encryption_value:
      return None

    value_data = policy_encryption_value.data

    algorithm = hashes.MD5()
    backend = backends.default_backend()
    digest_context = hashes.Hash(algorithm, backend=backend)

    digest_context.update(boot_key)

    iteration = 0
    while iteration < 1000:
      digest_context.update(value_data[60:76])
      iteration += 1

    rc4_key = digest_context.finalize()
    decrypted_data = self._DecryptARC4(rc4_key, value_data[12:60])
    return decrypted_data[16:32] 
开发者ID:libyal,项目名称:winreg-kb,代码行数:37,代码来源:cached_credentials.py

示例13: __init__

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [as 别名]
def __init__(self, data, **kwargs):

        ParsingDict.__init__(self, **kwargs)

        self.raw_data = data
        self.subject_cn = None
        self.subject_o = None
        self.subject_c = None
        self.issuer_cn = None
        self.issuer_o = None
        self.issuer_c = None

        self.valid_from = None
        self.valid_until = None

        self.checksum_md5 = None
        self.checksum_sha1 = None
        self.checksum_sha256 = None

        self.has_expired = None

        self.extensions = {}

        cert = x509.load_pem_x509_certificate(data.encode("ascii"), openssl.backend)

        if cert:
            self.checksum_md5 = self._colonify(cert.fingerprint(hashes.MD5()))
            self.checksum_sha1 = self._colonify(cert.fingerprint(hashes.SHA1()))
            self.checksum_sha256 = self._colonify(cert.fingerprint(hashes.SHA256()))

            self.valid_from = pytz.utc.localize(cert.not_valid_before)
            self.valid_until = pytz.utc.localize(cert.not_valid_after)

            self.has_expired = self._has_expired()

            self._add_extensions(cert)

        if cert and cert.subject:
            self.subject_cn, self.subject_o, self.subject_c = \
                self._parse_x509_name(cert.subject)

        if cert and cert.issuer:
            self.issuer_cn, self.issuer_o, self.issuer_c = \
                self._parse_x509_name(cert.issuer)

    # OID name lookup of the common abbreviations
    # In reality probably only CN will be used 
开发者ID:RIPE-NCC,项目名称:ripe-atlas-sagan,代码行数:49,代码来源:ssl.py

示例14: test_bad_cryptography_module_attribute_usage

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [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 import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import MD5 [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.hashes.MD5属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。