In: Computer Science
To demonstrate the practical implementation of the public\private encryption, you have been asked to compete the following task.
i. Type the following message in a .txt file: “My student ID is : >
ii. Download the public key given in this assignment folder and encrypt your message with the same key using openssl. iii. Using openssl, generate RSA key pair (2048bits) in your computer.
my student id is 40926
Public key encryption technique allows a person 'A' to send his public key to his friend 'B' through an open and insecure channel. Then, friend 'B' can use that public key to encrypt a message and return it to the original person 'A'. Moreover, this public key encrypted message can now be decrypted by the use of only its corresponding private key, which is present with person 'A' only.
OpenSSL, a free software, provides us the Secure Sockets Layer (SSL) protocol and enables us for secure communication.
Part 1: In this part we can create a file sample.txt with message " my student id is 40926" as following.
1. touch sample.txt
2. echo 'my student id is 40926' > sample.txt
Part 2: Assume that we have a given public in the ".pem" format as "public-key.pem", we can use the following command to encrypt the "sample .txt" file having a message "my student id is 40926" .
openssl rsautl -encrypt -in sample.txt -out sample_encrypted_file.txt -pubin -inkey public-key.pem
So after the above command, an encrypted file "sample_encrypted_file.txt" will get created, and we need a private key corresponding to the public-key.pem to decript it.
Further, to decript it and get the file "sample_decripted.txt" corresponding to the original file "sample.txt" we need to run the following command.
openssl rsautl -decrypt -in sample_encrypted_file.txt -out sample_decripted.txt -inkey private-key.pem
------------------------------------------------------------------------------------------------------------------------------------------------
Part 3: To generate the public/private key RSA pairs, we need to follow the following steps
1. Generate a private key using the following command.
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out private-key.pem
The above command will generate a private key "private-key.pem" using the RSA algorithm and having 2048 bit size.
2. Now, we need to generate a public key associated with this private key, according to the following command .
openssl pkey -in private-key.pem -out public-key.pem -pubout
Above command uses the "private-key.pem" private key and generates a public key "public-key.pem" associated to it.
Togeteher, step 1 and 2 generates the RSA public/private key pairs.
So, now person 'B' can encrypt a message using the public key "public-key.pem" which is given by person 'A' and send it to through the network. Moreover, 'A' can decrypt it using the associated private key "private-key.pem".
Further, details associted to the "openssl" can be found using following command.
openssl help