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