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


Python SHA1.new方法代码示例

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


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

示例1: addHmac

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def addHmac(string, Version):

        isHmacVersion = False

        # "Encrypt-then-MAC" feature introduced in R1 2017
        # Required for >= "2017.1.118" (e.g. "2017.1.118", "2017.1.228", "2017.2.503" etc.)

        if int(Version[:4]) >= 2017:
            isHmacVersion = True

        hmac = HMAC.new(
            bytes(RAUCipher.HASHKEY.encode()),
            string.encode(),
            SHA256.new()
            )

        hmac = base64.b64encode(hmac.digest()).decode()
        return string + hmac if isHmacVersion else string 
开发者ID:noperator,项目名称:CVE-2019-18935,代码行数:20,代码来源:RAU_crypto.py

示例2: test_verify

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def test_verify(self, tv):
        self._id = "Wycheproof ECDSA Test #%d (%s, %s)" % (tv.id, tv.comment, tv.filename)

        hashed_msg = tv.hash_module.new(tv.msg)
        signer = DSS.new(tv.key, 'fips-186-3', encoding=tv.encoding)
        try:
            signature = signer.verify(hashed_msg, tv.sig)
        except ValueError as e:
            if tv.warning:
                return
            if tv.comment == "k*G has a large x-coordinate":
                return
            assert not tv.valid
        else:
            assert tv.valid
            self.warn(tv) 
开发者ID:vcheckzen,项目名称:FODI,代码行数:18,代码来源:test_dss.py

示例3: runTest

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def runTest(self):

        key = RSA.generate(1280)
        signer = pss.new(key)
        hash_names = ("MD2", "MD4", "MD5", "RIPEMD160", "SHA1",
                      "SHA224", "SHA256", "SHA384", "SHA512",
                      "SHA3_224", "SHA3_256", "SHA3_384", "SHA3_512")

        for name in hash_names:
            hashed = load_hash_by_name(name).new(b("Test"))
            signer.sign(hashed)

        from Crypto.Hash import BLAKE2b, BLAKE2s
        for hash_size in (20, 32, 48, 64):
            hashed_b = BLAKE2b.new(digest_bytes=hash_size, data=b("Test"))
            signer.sign(hashed_b)
        for hash_size in (16, 20, 28, 32):
            hashed_s = BLAKE2s.new(digest_bytes=hash_size, data=b("Test"))
            signer.sign(hashed_s) 
开发者ID:vcheckzen,项目名称:FODI,代码行数:21,代码来源:test_pss.py

示例4: get_hash_module

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def get_hash_module(hash_name):
    if hash_name == "SHA-512":
        hash_module = SHA512
    elif hash_name == "SHA-512/224":
        hash_module = SHA512.new(truncate="224")
    elif hash_name == "SHA-512/256":
        hash_module = SHA512.new(truncate="256")
    elif hash_name == "SHA-384":
        hash_module = SHA384
    elif hash_name == "SHA-256":
        hash_module = SHA256
    elif hash_name == "SHA-224":
        hash_module = SHA224
    elif hash_name == "SHA-1":
        hash_module = SHA1
    else:
        raise ValueError("Unknown hash algorithm: " + hash_name)
    return hash_module 
开发者ID:vcheckzen,项目名称:FODI,代码行数:20,代码来源:test_pss.py

示例5: test_streaming

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def test_streaming(self):
        """Verify that an arbitrary number of bytes can be encrypted/decrypted"""
        from Crypto.Hash import SHA1

        segments = (1, 3, 5, 7, 11, 17, 23)
        total = sum(segments)

        pt = b("")
        while len(pt) < total:
            pt += SHA1.new(pt).digest()

        cipher1 = ChaCha20.new(key=b("7") * 32, nonce=b("t") * 8)
        ct = cipher1.encrypt(pt)

        cipher2 = ChaCha20.new(key=b("7") * 32, nonce=b("t") * 8)
        cipher3 = ChaCha20.new(key=b("7") * 32, nonce=b("t") * 8)
        idx = 0
        for segment in segments:
            self.assertEqual(cipher2.decrypt(ct[idx:idx+segment]), pt[idx:idx+segment])
            self.assertEqual(cipher3.encrypt(pt[idx:idx+segment]), ct[idx:idx+segment])
            idx += segment 
开发者ID:vcheckzen,项目名称:FODI,代码行数:23,代码来源:test_ChaCha20.py

示例6: test_verify

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def test_verify(self, tv):
        self._id = "Wycheproof ECDSA Test #%d (%s)" % (tv.id, tv.comment)

        hashed_msg = tv.hash_module.new(tv.msg)
        signer = DSS.new(tv.key, 'fips-186-3', encoding='der')
        try:
            signature = signer.verify(hashed_msg, tv.sig)
        except ValueError as e:
            if tv.warning:
                return
            if tv.comment == "k*G has a large x-coordinate":
                return
            assert not tv.valid
        else:
            assert tv.valid
            self.warn(tv) 
开发者ID:bkerler,项目名称:android_universal,代码行数:18,代码来源:test_dss.py

示例7: runTest

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def runTest(self):

        key = RSA.generate(1024)
        signer = pkcs1_15.new(key)
        hash_names = ("MD2", "MD4", "MD5", "RIPEMD160", "SHA1",
                      "SHA224", "SHA256", "SHA384", "SHA512",
                      "SHA3_224", "SHA3_256", "SHA3_384", "SHA3_512")

        for name in hash_names:
            hashed = load_hash_by_name(name).new(b"Test")
            signer.sign(hashed)

        from Crypto.Hash import BLAKE2b, BLAKE2s
        for hash_size in (20, 32, 48, 64):
            hashed_b = BLAKE2b.new(digest_bytes=hash_size, data=b"Test")
            signer.sign(hashed_b)
        for hash_size in (16, 20, 28, 32):
            hashed_s = BLAKE2s.new(digest_bytes=hash_size, data=b"Test")
            signer.sign(hashed_s) 
开发者ID:bkerler,项目名称:android_universal,代码行数:21,代码来源:test_pkcs1_15.py

示例8: verify_incoming_request

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def verify_incoming_request(form_data: dict) -> bool:
    """verify the incoming form_data"""
    # copy form data
    input_data = form_data.copy()

    signature = input_data["p_signature"]

    # Remove the p_signature parameter
    del input_data["p_signature"]

    # Ensure all the data fields are strings
    for field in input_data:
        input_data[field] = str(input_data[field])

    # Sort the data
    sorted_data = collections.OrderedDict(sorted(input_data.items()))

    # and serialize the fields
    serialized_data = phpserialize.dumps(sorted_data)

    # verify the data
    key = RSA.importKey(public_key_der)
    digest = SHA1.new()
    digest.update(serialized_data)
    verifier = PKCS1_v1_5.new(key)
    signature = base64.b64decode(signature)
    if verifier.verify(digest, signature):
        return True
    return False 
开发者ID:simple-login,项目名称:app,代码行数:31,代码来源:paddle_utils.py

示例9: hash_SHA512

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def hash_SHA512(data) -> str:
    if isinstance(data, str):
        hash_digest = SHA512.new(data=str.encode(data))
    else:
        hash_digest = SHA512.new(data=data)
    return hash_digest.hexdigest() 
开发者ID:its-a-feature,项目名称:Apfell,代码行数:8,代码来源:crypto.py

示例10: hash_SHA256

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def hash_SHA256(data) -> str:
    if isinstance(data, str):
        hash_digest = SHA256.new(data=str.encode(data))
    else:
        hash_digest = SHA256.new(data=data)
    return hash_digest.hexdigest() 
开发者ID:its-a-feature,项目名称:Apfell,代码行数:8,代码来源:crypto.py

示例11: hash_SHA1

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def hash_SHA1(data) -> str:
    if isinstance(data, str):
        hash_digest = SHA1.new(data=str.encode(data))
    else:
        hash_digest = SHA1.new(data=data)
    return hash_digest.hexdigest() 
开发者ID:its-a-feature,项目名称:Apfell,代码行数:8,代码来源:crypto.py

示例12: hash_MD5

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def hash_MD5(data) -> str:
    if isinstance(data, str):
        hash_digest = MD5.new(data=str.encode(data))
    else:
        hash_digest = MD5.new(data=data)
    return hash_digest.hexdigest()


# https://pycryptodome.readthedocs.io/en/latest/src/examples.html 
开发者ID:its-a-feature,项目名称:Apfell,代码行数:11,代码来源:crypto.py

示例13: decrypt_AES256

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def decrypt_AES256(data: bytes, key: bytes):
    # hmac should include IV
    mac = data[-32:]  # sha256 hmac at the end
    iv = data[:16]  # 16 Bytes for IV at the beginning
    message = data[16:-32]  # the rest is the message
    h = HMAC.new(key=key, msg=iv + message, digestmod=SHA256)
    h.verify(mac)
    decryption_cipher = AES.new(key, AES.MODE_CBC, iv=iv)
    decrypted_message = decryption_cipher.decrypt(message)
    # print(decrypted_message)
    # now to remove any padding that was added on to make it the right block size of 16
    return unpad(decrypted_message, 16) 
开发者ID:its-a-feature,项目名称:Apfell,代码行数:14,代码来源:crypto.py

示例14: encrypt_pub_key

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def encrypt_pub_key(data: bytes, key: bytes):
    recipient_key = RSA.import_key(key)
    cipher_rsa = PKCS1_OAEP.new(recipient_key)
    encrypted_data = cipher_rsa.encrypt(data)
    return encrypted_data 
开发者ID:its-a-feature,项目名称:Apfell,代码行数:7,代码来源:crypto.py

示例15: decrypt_pub_key

# 需要导入模块: from Crypto.Hash import SHA1 [as 别名]
# 或者: from Crypto.Hash.SHA1 import new [as 别名]
def decrypt_pub_key(data: bytes, key: bytes):
    recipient_key = RSA.import_key(key)
    cipher_rsa = PKCS1_OAEP.new(recipient_key)
    decrypted_data = cipher_rsa.decrypt(data)
    return decrypted_data 
开发者ID:its-a-feature,项目名称:Apfell,代码行数:7,代码来源:crypto.py


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