當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。