Python-rsa (Public private key production, encryption and decryption, signature)

Source: Internet
Author: User
Tags diff openssl rsa

    • Signing data with the RSA algorithm


    • Step1. Create private/public keypair (optional)
OpenSSL genrsa-out Private.pem 1024x768 >private.pem

This creates a key file called Private.pem. This file actually has both the private and public keys, so you should extract the public one from this file:

OpenSSL rsa-in private.pem-out public.pem-outform pem-pubout >public.pem

You're now having PUBLIC.PEM containing just your public key, and you can freely share this with 3rd parties.


    • Step2. Create a hash of the data
Echo ' data to sign ' > Data.txtopenssl dgst-md5 data.txt >data ' s MD5 code


    • Step3. Sign the hash using the private key
OpenSSL rsautl-sign-inkey private.pem-keyform pem-md5-out data.sign data.txt > signature

The file ' signature ' and the actual data ' data.txt ' can now is communicated to the receiving end. The hash algorithm (in we case MD5) as well as the public key must also is known to the receiving end.


    • Authenticate data using the public key


    • Step4. Create a hash of the data (same as Step 2)


    • Step5. Verify the signature
OpenSSL rsautl-verify-inkey public.pem-keyform pem-pubin-md5-signature-signature data.sign data.txt > verified
Diff-s verified Hash

If The result of the above command ' verified ' matches the hash generated in Step 3.1 (in which case you the result of the diff command would be ' Files verified and hash was identical ') then the signature is considered authentic and the Integrit Y/authenticity of the data is proven.


This article is from the "Mr_computer" blog, make sure to keep this source http://caochun.blog.51cto.com/4497308/1559636

Python-rsa (Public private key production, encryption and decryption, signature)

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.