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


Python hashes.SHA384属性代码示例

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


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

示例1: _get_key

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def _get_key(self, alg, key, p2s, p2c):
        if isinstance(key, bytes):
            plain = key
        else:
            plain = key.encode('utf8')
        salt = bytes(self.name.encode('utf8')) + b'\x00' + p2s

        if self.hashsize == 256:
            hashalg = hashes.SHA256()
        elif self.hashsize == 384:
            hashalg = hashes.SHA384()
        elif self.hashsize == 512:
            hashalg = hashes.SHA512()
        else:
            raise ValueError('Unknown Hash Size')

        kdf = PBKDF2HMAC(algorithm=hashalg, length=_inbytes(self.keysize),
                         salt=salt, iterations=p2c, backend=self.backend)
        rk = kdf.derive(plain)
        if _bitsize(rk) != self.keysize:
            raise InvalidJWEKeyLength(self.keysize, len(rk))
        return JWK(kty="oct", use="enc", k=base64url_encode(rk)) 
开发者ID:latchset,项目名称:jwcrypto,代码行数:24,代码来源:jwa.py

示例2: generate_signature

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def generate_signature(self, pri_key: str, msg: bytes) -> str:
        if self.__scheme == SignatureScheme.SHA224withECDSA:
            private_key = ec.derive_private_key(int(pri_key, 16), ec.SECP224R1(), default_backend())
            signature = private_key.sign(
                msg,
                ec.ECDSA(hashes.SHA224())
            )
        elif self.__scheme == SignatureScheme.SHA256withECDSA:
            private_key = ec.derive_private_key(int(pri_key, 16), ec.SECP256R1(), default_backend())
            signature = private_key.sign(
                msg,
                ec.ECDSA(hashes.SHA256())
            )
        elif self.__scheme == SignatureScheme.SHA384withECDSA:
            private_key = ec.derive_private_key(int(pri_key, 16), ec.SECP384R1(), default_backend())
            signature = private_key.sign(
                msg,
                ec.ECDSA(hashes.SHA384())
            )
        else:
            raise SDKException(ErrorCode.other_error('Invalid signature scheme.'))
        sign = SignatureHandler.dsa_der_to_plain(signature)
        return sign 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:25,代码来源:signature_handler.py

示例3: __init__

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def __init__(self, curve_class, nist_name):
        self.nist_name = nist_name
        self.key_length = curve_class.key_size

        # Defined in RFC 5656 6.2
        self.key_format_identifier = "ecdsa-sha2-" + self.nist_name

        # Defined in RFC 5656 6.2.1
        if self.key_length <= 256:
            self.hash_object = hashes.SHA256
        elif self.key_length <= 384:
            self.hash_object = hashes.SHA384
        else:
            self.hash_object = hashes.SHA512

        self.curve_class = curve_class 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:18,代码来源:ecdsakey.py

示例4: get_default_algorithms

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def get_default_algorithms():
    """
    Returns the algorithms that are implemented by the library.
    """
    default_algorithms = {
        'none': NoneAlgorithm(),
        'HS256': HMACAlgorithm(HMACAlgorithm.SHA256),
        'HS384': HMACAlgorithm(HMACAlgorithm.SHA384),
        'HS512': HMACAlgorithm(HMACAlgorithm.SHA512)
    }

    if has_crypto:
        default_algorithms.update({
            'RS256': RSAAlgorithm(RSAAlgorithm.SHA256),
            'RS384': RSAAlgorithm(RSAAlgorithm.SHA384),
            'RS512': RSAAlgorithm(RSAAlgorithm.SHA512),
            'ES256': ECAlgorithm(ECAlgorithm.SHA256),
            'ES384': ECAlgorithm(ECAlgorithm.SHA384),
            'ES512': ECAlgorithm(ECAlgorithm.SHA512),
            'PS256': RSAPSSAlgorithm(RSAPSSAlgorithm.SHA256),
            'PS384': RSAPSSAlgorithm(RSAPSSAlgorithm.SHA384),
            'PS512': RSAPSSAlgorithm(RSAPSSAlgorithm.SHA512)
        })

    return default_algorithms 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:27,代码来源:algorithms.py

示例5: get_default_algorithms

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def get_default_algorithms():
    """
    Returns the algorithms that are implemented by the library.
    """
    default_algorithms = {
        'none': NoneAlgorithm(),
        'HS256': HMACAlgorithm(HMACAlgorithm.SHA256),
        'HS384': HMACAlgorithm(HMACAlgorithm.SHA384),
        'HS512': HMACAlgorithm(HMACAlgorithm.SHA512)
    }

    if has_crypto:
        default_algorithms.update({
            'RS256': RSAAlgorithm(RSAAlgorithm.SHA256),
            'RS384': RSAAlgorithm(RSAAlgorithm.SHA384),
            'RS512': RSAAlgorithm(RSAAlgorithm.SHA512),
            'ES256': ECAlgorithm(ECAlgorithm.SHA256),
            'ES384': ECAlgorithm(ECAlgorithm.SHA384),
            'ES521': ECAlgorithm(ECAlgorithm.SHA512),
            'ES512': ECAlgorithm(ECAlgorithm.SHA512),  # Backward compat for #219 fix
            'PS256': RSAPSSAlgorithm(RSAPSSAlgorithm.SHA256),
            'PS384': RSAPSSAlgorithm(RSAPSSAlgorithm.SHA384),
            'PS512': RSAPSSAlgorithm(RSAPSSAlgorithm.SHA512)
        })

    return default_algorithms 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:28,代码来源:algorithms.py

示例6: __init__

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def __init__(self):
        super(_HS384, self).__init__(hashes.SHA384()) 
开发者ID:latchset,项目名称:jwcrypto,代码行数:4,代码来源:jwa.py

示例7: _oaep_hash_supported

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def _oaep_hash_supported(self, algorithm):
        if self._lib.Cryptography_HAS_RSA_OAEP_MD:
            return isinstance(
                algorithm, (
                    hashes.SHA1,
                    hashes.SHA224,
                    hashes.SHA256,
                    hashes.SHA384,
                    hashes.SHA512,
                )
            )
        else:
            return isinstance(algorithm, hashes.SHA1) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:backend.py

示例8: _verify_algorithm

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def _verify_algorithm(algorithm):
    if not isinstance(algorithm, _ALLOWED_HASHES):
        raise ValueError(
            "Algorithm must be SHA1, SHA224, SHA256, SHA384, or SHA512"
        ) 
开发者ID:tp4a,项目名称:teleport,代码行数:7,代码来源:ocsp.py

示例9: test_handle_symmetric_padding_undo

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [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

示例10: __init__

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def __init__(self, security_level=CURVE_P_256_Size, hash_algorithm=SHA2):
        """ Init curve and hash function.

        :param security_level: security level
        :param hash_algorithm: hash function
        :return: an instance of Ecies
        """
        if security_level == CURVE_P_256_Size:
            # order = openssl.backend._lib.BN_new()
            # curve = openssl.backend._lib.EC_GROUP_new_by_curve_name(
            #     openssl.backend._lib.NID_X9_62_prime256v1)
            # openssl.backend._lib.EC_GROUP_get_order(
            #     curve, order, openssl.backend._ffi.NULL)
            self.order = int("115792089210356248762697446949407573529"
                             "996955224135760342422259061068512044369")
            self.half_order = self.order >> 1
            self.curve = ec.SECP256R1
            self.sign_hash_algorithm = hashes.SHA256()
        else:
            # order = openssl.backend._lib.BN_new()
            # curve = openssl.backend._lib.EC_GROUP_new_by_curve_name(
            #     openssl.backend._lib.NID_secp384r1)
            # openssl.backend._lib.EC_GROUP_get_order(
            #     curve, order, openssl.backend._ffi.NULL)
            self.order = int("39402006196394479212279040100"
                             "14361380507973927046544666794"
                             "69052796276593991132635693989"
                             "56308152294913554433653942643")
            self.half_order = self.order >> 1
            self.curve = ec.SECP384R1
            self.sign_hash_algorithm = hashes.SHA384()

        if hash_algorithm == SHA2:
            self._hash = hashlib.sha256
        elif hash_algorithm == SHA3 and security_level == CURVE_P_256_Size:
            self._hash = hashlib.sha3_256
        else:
            self._hash = hashlib.sha3_384 
开发者ID:hyperledger,项目名称:fabric-sdk-py,代码行数:40,代码来源:crypto.py

示例11: __init__

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def __init__(self, key, algorithm, cryptography_backend=default_backend):
        if algorithm not in ALGORITHMS.RSA:
            raise JWKError('hash_alg: %s is not a valid hash algorithm' % algorithm)

        self.hash_alg = {
            ALGORITHMS.RS256: self.SHA256,
            ALGORITHMS.RS384: self.SHA384,
            ALGORITHMS.RS512: self.SHA512
        }.get(algorithm)
        self._algorithm = algorithm

        self.cryptography_backend = cryptography_backend

        # if it conforms to RSAPublicKey interface
        if hasattr(key, 'public_bytes') and hasattr(key, 'public_numbers'):
            self.prepared_key = key
            return

        if isinstance(key, dict):
            self.prepared_key = self._process_jwk(key)
            return

        if isinstance(key, six.string_types):
            key = key.encode('utf-8')

        if isinstance(key, six.binary_type):
            try:
                if key.startswith(b'-----BEGIN CERTIFICATE-----'):
                    self._process_cert(key)
                    return

                try:
                    self.prepared_key = load_pem_public_key(key, self.cryptography_backend())
                except ValueError:
                    self.prepared_key = load_pem_private_key(key, password=None, backend=self.cryptography_backend())
            except Exception as e:
                raise JWKError(e)
            return

        raise JWKError('Unable to parse an RSA_JWK from key: %s' % key) 
开发者ID:mpdavis,项目名称:python-jose,代码行数:42,代码来源:cryptography_backend.py

示例12: verify_certificate_algorithm

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def verify_certificate_algorithm(cert):
    valid_algorithm = False
    for alg in [SHA224, SHA256, SHA256, SHA384, SHA512]:
        if isinstance(cert.signature_hash_algorithm, alg):
            valid_algorithm = True
            break
    return valid_algorithm 
开发者ID:italia,项目名称:spid-testenv2,代码行数:9,代码来源:crypto.py

示例13: __init__

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def __init__(self, hmac_key, algorithm):
    """Constructor for Hmac.

    Args:
      hmac_key: bytes, the symmetric hmac key.
      algorithm: string, HMAC algorithm as defined at
        https://tools.ietf.org/html/rfc7518#section-3.1.

    Raises:
      TypeError: if the hmac key is not bytes.
      UnsupportedAlgorithm: if the algorithm is not supported or key is too
      short.
    """
    if algorithm == "HS256":
      self._hash = hashes.SHA256()
    elif algorithm == "HS384":
      self._hash = hashes.SHA384()
    elif algorithm == "HS512":
      self._hash = hashes.SHA512()
    else:
      raise exceptions.UnsupportedAlgorithm(
          "Unknown algorithm: %s " % (algorithm))
    if not isinstance(hmac_key, six.binary_type):
      raise TypeError("hmac key must be bytes")
    if len(hmac_key) < 16:
      raise exceptions.UnsupportedAlgorithm("key too short")
    self._hmac_key = hmac_key
    self.algorithm = algorithm 
开发者ID:google,项目名称:jws,代码行数:30,代码来源:hmac.py

示例14: __init__

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def __init__(self, pub_key, algorithm):
    """Constructor for EcdsaVerify.

    Args:
      pub_key: ec.EllipticCurvePublicKey, the Ecdsa public key.
      algorithm: string, Ecdsa algorithm as defined at
        https://tools.ietf.org/html/rfc7518#section-3.1.
    Raises:
      TypeError: if the public key is not an instance of
      ec.EllipticCurvePublicKey.
      UnsupportedAlgorithm: if the algorithm is not supported.
    """
    if not isinstance(pub_key, ec.EllipticCurvePublicKey):
      raise TypeError(
          "The public key must be an instance of ec.EllipticCurvePublicKey")
    self.pub_key = pub_key
    curve_name = ""
    if algorithm == "ES256":
      self.hash = hashes.SHA256()
      curve_name = "secp256r1"
    elif algorithm == "ES384":
      self.hash = hashes.SHA384()
      curve_name = "secp384r1"
    elif algorithm == "ES512":
      self.hash = hashes.SHA512()
      curve_name = "secp521r1"
    else:
      raise exceptions.UnsupportedAlgorithm(
          "Unknown algorithm : %s" % (algorithm))
    # In Ecdsa, both the key and the algorithm define the curve. Therefore, we
    # must cross check them to make sure they're the same.
    if curve_name != pub_key.curve.name:
      raise exceptions.UnsupportedAlgorithm(
          "The curve in public key %s and in algorithm % don't match" %
          (pub_key.curve.name, curve_name))
    self.algorithm = algorithm 
开发者ID:google,项目名称:jws,代码行数:38,代码来源:ecdsa_verify.py

示例15: parse_rsa_algorithm

# 需要导入模块: from cryptography.hazmat.primitives import hashes [as 别名]
# 或者: from cryptography.hazmat.primitives.hashes import SHA384 [as 别名]
def parse_rsa_algorithm(algorithm):
  """Parses Rsa's algorithm and returns tuple (hash, padding).

  Args:
    algorithm: string, RSA algorithm as defined at
    https://tools.ietf.org/html/rfc7518#section-3.1.

  Raises:
    UnsupportedAlgorithm: if the algorithm is not supported.

  Returns:
    (hash, padding) tuple.
  """

  if algorithm == "RS256":
    return (hashes.SHA256(), padding.PKCS1v15())
  elif algorithm == "RS384":
    return (hashes.SHA384(), padding.PKCS1v15())
  elif algorithm == "RS512":
    return (hashes.SHA512(), padding.PKCS1v15())
  elif algorithm == "PS256":
    return (hashes.SHA256(),
            padding.PSS(
                mgf=padding.MGF1(hashes.SHA256()),
                salt_length=padding.PSS.MAX_LENGTH))
  elif algorithm == "PS384":
    return (hashes.SHA384(),
            padding.PSS(
                mgf=padding.MGF1(hashes.SHA384()),
                salt_length=padding.PSS.MAX_LENGTH))
  elif algorithm == "PS512":
    return (hashes.SHA512(),
            padding.PSS(
                mgf=padding.MGF1(hashes.SHA512()),
                salt_length=padding.PSS.MAX_LENGTH))
  else:
    raise exceptions.UnsupportedAlgorithm("Unknown algorithm: %s" % (algorithm)) 
开发者ID:google,项目名称:jws,代码行数:39,代码来源:jwsutil.py


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