Key Concepts
- Public and Private Keys: GPG uses a pair of keys – a public key and a private key.
- Public Key: This key is shared openly and used to encrypt data.
- Private Key: This key is kept secret and used to decrypt data encrypted with the corresponding public key.
Encryption: The process of converting plaintext into ciphertext using a key.
Decryption: The process of converting ciphertext back into plaintext using a key.
Digital Signatures: A cryptographic signature that verifies the sender’s identity and ensures that the data has not been tampered with.
How GPG Works
- Generating Keys To use GPG, you first need to generate a pair of keys. This can be done using the following command:
gpg --gen-key
- Distributing the Public Key Once the keys are generated, you can distribute your public key to others so they can send you encrypted messages. Export your public key with:
gpg --export -a "Your name" \
> plublic_key.asc
You can then share public_key.asc with anyone who wants to send you encrypted messages.
- Importing Public Keys To encrypt a message to someone else, you need their public key. You can import their public key into your GPG keyring:
gpg --import public_key.asc
- Encrypting Messages To send an encrypted message, you use the recipient’s public key:
gpg --encrypt --recipient \
recipient@ss.com message.txt
This command will create an encrypted version of message.txt, typically with a .gpg extension.
- Decrypting Messages
gpg --decrypt message.txt.gpg
You will be prompted to enter the passphrase for your private key.
- Signing Messages To sign a message or file, you use your private key to create a digital signature:
gpg --sign message.txt
This command will create a signed version of message.txt (e.g., message.txt.gpg) that includes the digital signature.
- Verifying Signatures When you receive a signed message, you can verify the signature using the sender’s public key:
gpg --verify message.txt.gpg
This command will check the signature and confirm whether the message was signed by the corresponding private key and whether the message has been altered.
Combining Encryption and Signing
gpg --encrypt --sign --recipient\
recipient@ss.com message.txt
comments powered by Disqus