Cryptography v2
Cryptography v2
Cryptography v2
Spring 2021
Quiz 2
Cryptography
Objectives:
1. Install GPG
2. Generate Keypairs
3. Manage keys
5. Sign documents
This lab is inspired from the following resources: Mike Ashley about PGP (https://www.gnupg.org/gph/fr/manual.html)
, Guide about Yubikey and GPG (https://github.com/drduh/YubiKey-Guide).
SEC 336: Information Security Technologies
Spring 2021
3. GPG is installed and ready to go! Check the version of the installed tool and the supported
encryption algorithms by typing:
gpg -h
As you see from the output of the above command, GnuPG can create different types of
keypairs. The primary pair is used make signature operations, whereas the second pair is used
for encrypting. The different choices proposed by the gpg are the following:
Choice 1: It allows to create two RSA keypairs, the first keypair is used for signature and the
second one for encryption.
Choice 2: It allows to create two keypairs, the first one is DSA used for signature and the second
one is Elgamal is used for encryption.
This lab is inspired from the following resources: Mike Ashley about PGP (https://www.gnupg.org/gph/fr/manual.html)
, Guide about Yubikey and GPG (https://github.com/drduh/YubiKey-Guide).
SEC 336: Information Security Technologies
Spring 2021
3. For the Key size: The longer the key, the more resistant it will be against an attack, but it
requires a longer processing time. We currently consider that 2048 bits is a minimum to have
security for a few years. Type 2048 and press Enter
4. For the expiration Date: It must be chosen with care, because it is difficult to send the key with
the updated date to users who already have your expired public key. For this lab, type 0 and
press Enter, then type Y to confirm
5. For the identity: Before being distributed, the key must be linked to an identity. To do this, we
will attach the key pairs to an identifier (i.e. your mail address). For the purpose of this lab, you
can use your personal email address if you are creating the keys on your own device and you
want to adopt the keys that you create for your personal use. Insert your name, email address,
and comment if needed then press Enter. Type O to confirm if all the details are correct
6. A pop-up window will appear for you to enter a Password. As a final step, you should provide a
password that will be used to prove your identity when you wish to modify or use your private
keys (e.g. for signing documents). For this lab, Choose an easy-to-remember phrase that you
won’t forget. This password is used to generate a symmetric key which encrypts and decrypts
the database where your private keys are stored.
7. Once you provided all the above information, gpg generates the keypairs and give you
information about the identifier of your keypairs and their types (e.g. 2048 bits, RSA). - -
This lab is inspired from the following resources: Mike Ashley about PGP (https://www.gnupg.org/gph/fr/manual.html)
, Guide about Yubikey and GPG (https://github.com/drduh/YubiKey-Guide).
SEC 336: Information Security Technologies
Spring 2021
gpg --list-secret-keys
2. Exporting keys: You might have to copy your key to another machine to use the same key there,
you can export your private key using the following command:
gpg --armor --export-secret-keys InsertIdentifierEmailHere > private.key
This lab is inspired from the following resources: Mike Ashley about PGP (https://www.gnupg.org/gph/fr/manual.html)
, Guide about Yubikey and GPG (https://github.com/drduh/YubiKey-Guide).
SEC 336: Information Security Technologies
Spring 2021
This lab is inspired from the following resources: Mike Ashley about PGP (https://www.gnupg.org/gph/fr/manual.html)
, Guide about Yubikey and GPG (https://github.com/drduh/YubiKey-Guide).
SEC 336: Information Security Technologies
Spring 2021
you can later import the key on another machine using the command: gpg --import private.key
4. Creating keys: You can add different sub keypairs that can be used for different purposes. For
example, one sub keypair can be used for signing business documents while the other keypair
for signing personal documents. To add more sub keypairs, follow these steps:
a. Enter the editing mode of the primary key using this command:
gpg --edit-key InsertIdentifierEmailHere
This lab is inspired from the following resources: Mike Ashley about PGP (https://www.gnupg.org/gph/fr/manual.html)
, Guide about Yubikey and GPG (https://github.com/drduh/YubiKey-Guide).
SEC 336: Information Security Technologies
Spring 2021
5. Deleting keys: To delete an existing key, you should execute the following commands:
a. Enter in the editing mode of the primary key using this command:
gpg --edit-key InsertIdentifierEmailHere
where N represents the order of the key and can take values starting from 0.
6. Revoking keys: Sometimes, our private keys can be lost (e.g. your hard disk is crashed or stolen,
or you may simply forget your passphrase). In this case, we should inform our correspondents as
quickly as possible by revoking our key and sending them the revocation certificate. In order to
revoke a key, you need to know the passphrase of the private key that you want to revoke, and
you need to have an access to the private key. Follow the below steps to revoke a key:
This lab is inspired from the following resources: Mike Ashley about PGP (https://www.gnupg.org/gph/fr/manual.html)
, Guide about Yubikey and GPG (https://github.com/drduh/YubiKey-Guide).
SEC 336: Information Security Technologies
Spring 2021
b. Select the key to revoke using the below command, where N is the order number of the
key, starting from 0:
key N
7. Distributing keys: In an ideal scenario, we should distribute our keys by giving them personally
to our correspondents. However, the PGP keys can be distributed by email, or by other
electronic means of communication. In addition to email, one of the most known distribution
methods is to post your public key to central public key servers. Use the following command to
distribute your key:
This lab is inspired from the following resources: Mike Ashley about PGP (https://www.gnupg.org/gph/fr/manual.html)
, Guide about Yubikey and GPG (https://github.com/drduh/YubiKey-Guide).
SEC 336: Information Security Technologies
Spring 2021
f. Use the command ls to view the output file, which should be titled doc1.gpg
g. View the contents of the encrypted file using the below command
cat doc1.gpg
- If you want to send the above encrypted message to a friend. What does your friend need
to decrypt the file? what is the problem that rises when using symmetric encryption?
2. Next, encrypt using asymmetric encryption. You can encrypt a message for a single specific
recipient. You do this by encrypting asymmetrically with the recipient’s public key. By doing this,
only the recipient's private key will decrypt the message. You will need the recipient's public key
in order to do this. They can share their public key with you directly, or you can search public
key servers. For this exercise you will encrypt using your own public key.
a. create the document that is going to be encrypted
touch doc2
This lab is inspired from the following resources: Mike Ashley about PGP (https://www.gnupg.org/gph/fr/manual.html)
, Guide about Yubikey and GPG (https://github.com/drduh/YubiKey-Guide).
SEC 336: Information Security Technologies
Spring 2021
For example:
gpg --output encrypted --encrypt --recipient [email protected] doc2
g. View the contents of the encrypted file using the below command.
cat encrypted
h. Now you will decrypt the file using the following command:
gpg --output decrypted --decrypt encrypted
j. View the contents of the encrypted file using the below command.
cat decrypted
- If Alice wants to send a message to bob using asymmetric cryptography. Which key should
she use to encrypt the message? And which key will be used to decrypt the message?
This lab is inspired from the following resources: Mike Ashley about PGP (https://www.gnupg.org/gph/fr/manual.html)
, Guide about Yubikey and GPG (https://github.com/drduh/YubiKey-Guide).