INTE2625 Week 5 Lab Manual
INTE2625 Week 5 Lab Manual
Objectives
In this Lab, you are going to learn asymmetric/public key encryption and decryption using
an open-source tool called GnuPG. We assume that you have already practiced symmetric key
encryption using GPG in Week 4. Please refer to Week 4 lab if you have not practiced that yet.
For more information on GPG, please visit: https://www.gnupg.org/
In this task, you will use two users of Kali Linux: kali (the default user) and alice (that you have
already created in Week 2 lab). If you have not created any user in your Kali Linux yet, refer to
Week 2 lab and create one.
1
Task-1.2: Generate RSA key-pair in GPG for the recipient Alice.
As discussed in the lecture, public-key encryption algorithm requires two keys: public and
private keys.
Login as the user alice (see previous labs). Use the following command in the Kali Linux
terminal to generate a key pair for the user alice:
You will be prompted to provide different information. You should provide as follows:
Confirm it by typing y:
2
You may be asked for a passkey. If so, provide one:
The keys are generated in a hidden directory /root/.gnupg which in the user root’s home
directory as the key was created using sudo privilege. You can view it by navigating to the user
root’s home directory by typing sudo ls -a /root.
3
Task-1.3: Making RSA Public key of Alice available to other users.
To communicate with others, public key of alice should be exported. Use the following
command to export the public key in text format (the default is binary format):
Here,
--export: This option tells gpg to export the public key. By default, this will export the
public key in binary format unless additional options are provided.
--armor: This option tells gpg to create ASCII-armored output instead of binary. ASCII
armor is a text-based encoding that allows the public key to be easily shared via email or
text files.
[email protected]: This specifies the user ID of the key to be exported. GPG uses
email addresses or other identifiers to locate the key within the keyring.
alice_public.gpg: This is the name of the file where the exported public key will be
saved. The > alice_public.gpg part of the command ensures that the output is written to
this file.
Now, share the public key file ‘alice_public.gpg’ with the user kali (refer to Week 4 lab for file
sharing between users).
We are assuming that you have shared the public key file to the user kali and the file is
currently in the home directory (/home/kali or ~). Now, use the following command to import
the public key file in the user kali’s key-ring:
4
Check if it’s in the user kali’s key-ring:
Now, the user kali will encrypt the file ‘test.txt’ using alice’s public key (accessed using Alice’s
key-id: [email protected]) and generate an encrypted file with a name ‘encrypted_test.txt’.
The command is as below:
Here,
--encrypt: This option tells gpg to encrypt the specified file.
--output encrypted_test.txt: This specifies the name of the file where the encrypted
output will be saved. In this case, the encrypted content will be written to
encrypted_test.txt.
--recipient [email protected]: This option specifies the recipient of the encrypted
file. GPG will look for the public key associated with [email protected] in your
keyring and use it to encrypt the file. Only the private key corresponding to this
public key can decrypt the file.
test.txt: This is the name of the file to be encrypted. GPG will read the contents of
this file, encrypt it, and then write the encrypted data to the output file specified by
the --output option.
Now, check if the encrypted file has been created or not. You should see the following output by
running ls command:
5
You may check the contents of the encrypted file using cat command:
Login as user alice. Now, run the following command at the user alice’s side to decrypt the file
‘encrypted_test.txt’:
Here,
--output decrypted_test.txt: This specifies the name of the file where the decrypted
output will be saved. In this case, the decrypted content will be written to
decrypted_test.txt.
--decrypt: This option tells gpg to decrypt the specified file. GPG will use the
appropriate private key from your keyring to decrypt the file.
encrypted_test.txt: This is the name of the file to be decrypted. GPG will read the
contents of this encrypted file, decrypt it, and then write the decrypted data to the
output file specified by the --output option.
A passphrase may be asked. This is the passphrase that alice used during the creation of the
key:
6
File has been decrypted which can be checked as follows:
The content of the decrypted file can be checked using the cat command:
Congratulations! You have now completed the public-key encryption and decryption using GPG.