Lab - 5 - Encrypting
Lab - 5 - Encrypting
GnuPG is already pre-installed in Kali Linux. Check by typing the following command:
if which gpg >/dev/null; then
echo "Installed"
# ...
fi
Not installed, you can install GPG with the following command for GnuPG package
sudo apt-get install gnupg
What kind of key algorithm you want. Press '1' and ENTER.
[1] Next is the key size. Press ENTER to accept the default of 2048
[2] Key Validation: Press '1' and ENTER. (For one day validation)
[3] Then Answer 'y', then ENTER.
You can also use the following command to list the keys in your keyrings:
gpg --list-keys
Export the Public key from the keyring to a file In ASCII Format
gpg --export -a USERID> public.txt
Export the Private key from the keyring to a file In ASCII Format
gpg --export-secret-keys -a USERID > private.txt
Create a plain text file called "yourname.txt" using your favorite text editor (Vi, Vim or nano text
editor)
gedit yourname.txt
Use the -e or --encrypt option to encrypt a file for particular user (-r) with an ASCII encoding (-
a)
gpg -a -e -r [email protected] yourname.txt
Verify that you now have encrypted files present in your directory:
ls -l yourname.txt*
create digital signature for your file. You will be asked to enter your passphrase to unlock the
private key which is used for signing the document
With GnuPG, there are multiple methods of signing a file: gpg --output file.sig --clearsign file.txt
gpg --armor --output file.sig --sign file.txt
$ gpg --help | grep -i sign
You can use –detach-sign option to create a detached signature ( new file is created as signature)
$ gpg -a -o file.sig --detach-sig file.txt
you can list the signatures’s that got generated using the following command
$ gpg --list-sigs
When you receive keys, save the attachment and add it to your keyring (look for an "import"
option) or do this from the command line:
gpg –import public.txt
Upload your public key plus digital Signature along with the data to blackboard so your
instructor can verify it. (Public key + Digital Signature file + Text file)
To decrypt a file with GnuPG/PGP, all you can use -d or --decrypt to type the following
command:
gpg -d yourname.txt.asc
verify digital signature. In order to verify a detached signature, you need to have both the
signature file and the data file
To decrypt a file with GnuPG/PGP, all you can use -d or --decrypt to type the following
command:
gpg -d yourname.txt.asc
Editing a GPG key
You can change expiration dates and passwords, sign or revoke keys, and add and remove emails
and photos by typing this command:
gpg --edit-key USERID
After this, you need to import the revocation certificate into your public keyring: