For details about how to read and decrypt public and private keys in python

Source: Internet
Author: User

For details about how to read and decrypt public and private keys in python

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 );

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.