OS Lab Week 3: Cryptography

Introduction

In Operating Systems Lab Week 3 we were tasked to create a key-pair to allow us to encrypt and decrypt files then we exchanged encrypted files containing messages to other classmates in the lab group.

GNU Privacy Guard (GPG) software is used to generate our private and public key-pairs which is then used to encrypt and decrypt files. We then exchanged our encrypted files to other classmates.

Generating key-pair

To generate your own private and public key the ‘gpg –generate-full-key’ command must be used. GPG will prompt you for the following:

  • Type of key – select ‘(1) RSA and RSA’
  • Key size – enter ‘4096’
  • How long is it valid for – enter 1 month and yes
  • Enter your own personal details and email
  • A password

After following the instructions above, your public and private key will be generated

Export key as a file

The next step is to export your public key as a .key file. To do this enter the command ‘gpg –output <email>.key –export <email>”. Verify that the file has been created by entering the command ‘ls’, this will print a list of files and folder in your working directory, check if your .key file is there.

This .key file is your public key, you can share this to anyone you trust. However, the public key must be kept to your self, NEVER share your private key!

You can email this key to a person of your choice, for example your lab classmate.

Exporting your key as text

To export your public key as text enter the command ‘gpg –armor –export <email>’. GPG will then print out a block of text contained within ‘—–BEGIN PGP PUBLIC KEY BLOCK—–‘ and ‘—–END PGP PUBLIC KEY BLOCK—–‘. This block of text is your key and you can copy it

Sending an encrypted message

Importing key

To send an encrypted message to a recipe, you must receive their public key and import it into GPG. Start by first downloading the .key file sent to you by the recipient. Navigate to the directory of the .key file in your terminal and enter the command ‘gpg –import <file name>.key’

Encrypting message

Once you have imported the recipient’s public key into GPG you can now encrypt a file targeted for them. Firstly you must have a file to encrypt before hand, for example have a .txt file with a message inside it, then you will use the following command to encrypt it ‘gpg –output <encrypted file name> –encrypt –recipient <recipient email> <file name>’. GPG will generate a new encrypted file. This encrypted file can now be sent to the recipient.

Receiving an encrypted message

When you receive an encrypted message, to see it’s contents you must decrypt it using your private key. Enter the command ‘gpg –output <decrypted file name> –decrypt <encrypted file name>’. Now the decrypted file should be generated to your working directory. Check if this file exists by entering ‘ls’.

Conclusion

If you want to send me an encrypted message use my public key attached below 🙂

-----BEGIN PGP PUBLIC KEY BLOCK-----

mQINBGIES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