This article describes how to read the public/private key for encryption/decryption in python, for more information about how to read the public and private keys for encryption and decryption instances in python, see the following article.
Read the public/private key in python for encryption and decryption.
In RSA, one application mode is public key encryption and private key decryption (the other is private key signature and public key verification ). The following is an example of an application in Python.
Suppose I have a public key file, rsa_pub.pem. I want to read this public key and use it to encrypt it.
From M2Crypto import RSA, BIO fp = file ('RSA _ pub. pem', 'RB'); pub_key_str = fp. read (); fp. close (); mb = BIO. memoryBuffer (pub_key_str); pub_key = RSA. load_pub_key_bio (mb); data = '000000'; en_data = pub_key.public_encrypt (data, RSA. pkcs1_padding );...
Private key file rsa_private.pem, which reads the private key and is used for decryption
From M2Crypto import RSA, BIO private_key_str = file ('RSA _ private. pem', 'RB '). read (); private_key = RSA. load_key_string (private_key_str); data = 'sdfdjslfjaskldfjdskljsd'; de_data = private_key.private_decrypt (data, RSA. pkcs1_padding );
The above is a detailed description of the example of reading the public/private key for encryption and decryption in python. For more information, see other related articles in the first PHP community!