DEV Community

SilvenLEAF
SilvenLEAF

Posted on • Updated on

GPG/PGP Encryption Decryption

GPG Encryption Decryption

How does this work?

  • [x] generate SECRET_KEY to encrypt files
  • [x] share this SECRET_KEY to decrypter machine
  • [x] import this SECRET_KEY on encrypter machine
  • [x] encrypt file using this SECRET_KEY
  • [x] send this encrypted file to the decrypter machine
  • [x] decrypt the file using the SECRET_KEY on decrypter machine

Decrypter Machine

  • [x] generate gpg key using this command
gpg --gen-key
Enter fullscreen mode Exit fullscreen mode

or use this command

gpg --full-gen-key
Enter fullscreen mode Exit fullscreen mode
  • [x] list out your keys using this command
gpg --list-keys
Enter fullscreen mode Exit fullscreen mode
  • [x] export your key using this command (to send to encrypter)
gpg --export -a YOUR_KEY_ID > YOUR_FILE_NAME.asc
Enter fullscreen mode Exit fullscreen mode

This will generate a file. You can share this file to the Encrypter Machine. They'll import this key and encrypt the file using this key which you can later on decrypt on your machine.

Encrypter Machine

  • [x] import the SECRET_KEY of the decrypter
gpg --import YOUR_SECRET_KEY_FILE_NAME.asc
Enter fullscreen mode Exit fullscreen mode
  • [x] list out your keys using this command
gpg --list-keys
Enter fullscreen mode Exit fullscreen mode
  • [x] encrypt the pgp file
gpg --encrypt --recipient SECRET_KEY_ID --output ENCRYPTED_FILE FILE_TO_ENCRYPT
Enter fullscreen mode Exit fullscreen mode

share this encrypted file to your decrypter machine

Decrypter Machine

  • [x] decrypt the file
 gpg --decrypt --recipient SECRET_KEY_ID --passphrase YOUR_PASSWORD --output DECRYPTED_FILE ENCRYPTED_FILE
Enter fullscreen mode Exit fullscreen mode

yippie banzai we did it!

Top comments (0)