Experiment with asymmetric keys. first generate a public/secret key pair using R
ID: 3603414 • Letter: E
Question
Experiment with asymmetric keys.
first generate a public/secret key pair using RSA. generate a private key (“privatekey.pem”) using this command
>> openssl genrsa -out private-key.pem 1024
and the corresponding public key
(“public-key.pem”) using this command: >> openssl rsa -in private-key.pem -pubout -out public-key.pem
2. Now you are ready to encrypt some data. Create a very small text file, say input.txt.
To encrypt this file, do this: >> openssl rsautl -encrypt -pubin -inkey public-key.pem -in input.txt -out input.enc
This will generate an encrypted output file called “input.enc”.
To decrypt the file, do >> openssl rsautl -decrypt -inkey private-key.pem -in input.enc -out answer.txt This will generate a decrypted version of “input.enc” called “answer.txt”. You can verify that answer.txt and input.txt are the same by comparing the hash outputs.
Question 1. Create an input file that is similar to the input.txt file you created before (e.g. extra spacing, punctuation, etc.). Encrypt the file using the same key as before. What can you observe from the encrypted cipher text?
Explanation / Answer
#include #include #include using namespace std; //parseString //INPUT: // inputString : the entire line you read from file //OUTPUT: // plainText : a string reference, which will include everything except the integer in the front // key : an int reference. This will be the key taken from the beginning of the line void parseString(string inputString, string& plainText, int& key); string encryption(string plainText, int key); string decryption(string plainText, int key); int main() { ifstream infile; string tempString; string plaintext; int key = 0; infile.open("plaintext.txt"); while(!infile.eof()) { getline(infile, tempString, ' '); //read line until newline is encountered parseString(tempString, plaintext, key); coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.