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


Python PKCS1_v1_5.new方法代码示例

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


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

示例1: verify

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def verify(self, message, signature):
      """Verifies a message against a signature.

      Args:
        message: string, The message to verify.
        signature: string, The signature on the message.

      Returns:
        True if message was signed by the private key associated with the public
        key that this object was constructed with.
      """
      try:
        return PKCS1_v1_5.new(self._pubkey).verify(
            SHA256.new(message), signature)
      except:
        return False 
开发者ID:mortcanty,项目名称:earthengine,代码行数:18,代码来源:crypt.py

示例2: testSign1

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def testSign1(self):
                for i in range(len(self._testData)):
                        row = self._testData[i]
                        # Build the key
                        if isStr(row[0]):
                                key = RSA.importKey(row[0])
                        else:
                                comps = [ long(rws(row[0][x]),16) for x in ('n','e','d') ]
                                key = RSA.construct(comps)
                        h = row[3].new()
                        # Data to sign can either be in hex form or not
                        try:
                            h.update(t2b(row[1]))
                        except:
                            h.update(b(row[1]))
                        # The real test
                        signer = PKCS.new(key)
                        self.failUnless(signer.can_sign())
                        s = signer.sign(h)
                        self.assertEqual(s, t2b(row[2])) 
开发者ID:mortcanty,项目名称:earthengine,代码行数:22,代码来源:test_pkcs1_15.py

示例3: testVerify1

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def testVerify1(self):
                for i in range(len(self._testData)):
                        row = self._testData[i]
                        # Build the key
                        if isStr(row[0]):
                                key = RSA.importKey(row[0]).publickey()
                        else:
                                comps = [ long(rws(row[0][x]),16) for x in ('n','e') ]
                                key = RSA.construct(comps)
                        h = row[3].new()
                        # Data to sign can either be in hex form or not
                        try:
                            h.update(t2b(row[1]))
                        except:
                            h.update(b(row[1]))
                        # The real test
                        verifier = PKCS.new(key)
                        self.failIf(verifier.can_sign())
                        result = verifier.verify(h, t2b(row[2]))
                        self.failUnless(result) 
开发者ID:mortcanty,项目名称:earthengine,代码行数:22,代码来源:test_pkcs1_15.py

示例4: _build_auth_token_data

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def _build_auth_token_data(
        self,
        auth_token_ticket,
        authenticator,
        private_key,
        **kwargs
    ):
        auth_token = dict(
            authenticator=authenticator,
            ticket=auth_token_ticket,
            **kwargs
            )
        auth_token = json.dumps(auth_token, sort_keys=True)
        if six.PY3:
            auth_token = auth_token.encode('utf-8')
        digest = SHA256.new()
        digest.update(auth_token)
        auth_token = base64.b64encode(auth_token)
        rsa_key = RSA.importKey(private_key)
        signer = PKCS1_v1_5.new(rsa_key)
        auth_token_signature = signer.sign(digest)
        auth_token_signature = base64.b64encode(auth_token_signature)
        return auth_token, auth_token_signature 
开发者ID:discogs,项目名称:python-cas-client,代码行数:25,代码来源:cas_client.py

示例5: __init__

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def __init__(self, privatekey_text = None, pass_phrase= None):
        print('Initializing KeyManager...')
        if privatekey_text:
            self.import_key_pair(privatekey_text, pass_phrase)
        else:
            random_gen = Crypto.Random.new().read
            self._private_key = RSA.generate(2048, random_gen)
            self._public_key = self._private_key.publickey()
            self._signer = PKCS1_v1_5.new(self._private_key)
            if pass_phrase is not None:
                my_pem = self.export_key_pair(pass_phrase)
                my_pem_hex = binascii.hexlify(my_pem).decode('ascii')
                # とりあえずファイル名は固定
                path = 'my_server_key_pair.pem'
                f1 = open(path,'a')
                f1.write(my_pem_hex)
                f1.close() 
开发者ID:peaks-cc,项目名称:cryptocurrency-samplecode,代码行数:19,代码来源:key_manager.py

示例6: test_encrypt

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def test_encrypt(self, sign_message, encrypt_message, encrypt_key, get_key, get_iv):
        message = Random.new().read(2000)
        encryption = Encryption(self.sender_key, self.recipient_key)
        sender_key_bytes = int(self.sender_key.publickey().n.bit_length() / 8)
        encrypt_message.return_value = Random.new().read(len(message))
        encrypt_key.return_value = Random.new().read(sender_key_bytes)
        get_iv.return_value = Random.new().read(16)

        encrypted_message = encryption.encrypt(message)

        data = base64.b64decode(encrypted_message)
        iv = data[0:16]
        encrypted_key = data[16:(16 + sender_key_bytes)]
        encrypted_message = data[(16 + sender_key_bytes):]

        self.assertEqual(encrypt_message.return_value, encrypted_message)
        self.assertEqual(encrypt_key.return_value, encrypted_key)
        self.assertEqual(get_iv.return_value, iv)
        encrypt_key.assert_called_once_with(get_key.return_value)
        encrypt_message.assert_called_once_with(
            sign_message.return_value, message, get_key.return_value, get_iv.return_value
        )
        sign_message.assert_called_once_with(message) 
开发者ID:pedroburon,项目名称:tbk,代码行数:25,代码来源:test_encryption.py

示例7: test_decrypt

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def test_decrypt(self, verify, get_message, get_signature, get_decrypted_message, get_key, get_iv, hexlify):
        decryption = Decryption(self.recipient_key, self.sender_key)
        raw = Random.new().read(2000)
        encrypted = base64.b64encode(raw)
        message = get_message.return_value
        signature = get_signature.return_value
        hexlify_signature = hexlify.return_value
        decrypted_message = get_decrypted_message.return_value
        iv = get_iv.return_value
        key = get_key.return_value
        verify.return_value = True

        returned_message, returned_signature = decryption.decrypt(encrypted)

        self.assertEqual(message, returned_message)
        self.assertEqual(hexlify_signature, returned_signature)
        get_message.assert_called_once_with(decrypted_message)
        get_decrypted_message.assert_called_once_with(iv, key, raw)
        get_iv.assert_called_once_with(raw)
        get_key.assert_called_once_with(raw)
        get_signature.assert_called_once_with(decrypted_message)
        verify.assert_called_once_with(signature, message)
        hexlify.assert_called_once_with(signature) 
开发者ID:pedroburon,项目名称:tbk,代码行数:25,代码来源:test_encryption.py

示例8: sign

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def sign(self, msg, key):
        return PKCS1_v1_5.new(key).sign(self.hash_alg.new(msg)) 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:4,代码来源:pycrypto.py

示例9: verify

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def verify(self, msg, key, sig):
        return PKCS1_v1_5.new(key).verify(self.hash_alg.new(msg), sig) 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:4,代码来源:pycrypto.py

示例10: sign_data

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def sign_data(data: bytes, private_key: RSA):
    """
    Signs message
    :param data: message to sign 
    :param private_key: private key to use
    :return: 
    """
    signer = PKCS1_v1_5.new(private_key)
    digest = SHA256.new()
    digest.update(data)
    return signer.sign(digest) 
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:13,代码来源:crypto.py

示例11: verify_data

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def verify_data(data: bytes, signature: bytes, public_key: RSA) -> bool:
    """
    Verifies message 
    :param data: Message to verify
    :param signature: signature of message to verify
    :param public_key: public key to use
    :return: 
    """
    signer = PKCS1_v1_5.new(public_key)
    digest = SHA256.new()
    digest.update(data)
    return signer.verify(digest, signature) 
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:14,代码来源:crypto.py

示例12: calculate_fingerprint

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def calculate_fingerprint(pkey: paramiko.pkey.PKey, algorithm: str='md5') -> bytes:
    """
    Calculates fingerprint for PKey
    :param pkey: pkey
    :param algorithm: algoright to use 
    :return: fingerprint
    """

    h = hashlib.new(algorithm)
    h.update(pkey.asbytes())
    return h.digest() 
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:13,代码来源:crypto.py

示例13: verify_incoming_request

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 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

示例14: verify

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def verify(self, message, signature):
        hash = SHA256.new(message)
        signer = PKCS1_v1_5.new(self._value)
        return signer.verify(hash, signature) 
开发者ID:google,项目名称:rekall,代码行数:6,代码来源:crypto.py

示例15: client_id

# 需要导入模块: from Crypto.Signature import PKCS1_v1_5 [as 别名]
# 或者: from Crypto.Signature.PKCS1_v1_5 import new [as 别名]
def client_id(self):
        return "C.%s" % (SHA256.new(self._value.publickey().exportKey(
            "PEM")).hexdigest()[:16]) 
开发者ID:google,项目名称:rekall,代码行数:5,代码来源:crypto.py


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