Skip to content

codylane/bash-gpg-sae

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

gpg-sae

A little bash utility for signing and decrypting files

Prerequisite or Helpful links

Usage

Configuration

This utility was created to be as minimalist as possible, however, there are a few configuration settings you can apply in your environment.

Environment Variable Description Example
GPG_KEY_ID YOUR primary key id to be used encrypt/decrypt functions. Used for gpg arg (-r, --recipient USER-ID) GPG_KEY_ID=CodyLane
DELETE_NON_ENCRYPTED_FILE_AFTER_ENCRYPT When set to Y the default, the original file is deleted after encryption DELETE_NON_ENCRYPTED_FILE_AFTER_ENCRYPT=Y

Example encrypting a file

  • Creates an example file called encrypt_this_file that we will encrypt
cat > encrypt_this_file <<EOF
this is my special file that I would like to encrypt
EOF
  • Ensure the file contains our text

cat encrypt_this_file

this is my special file that I would like to encrypt
  • First we get a list of our keys and fingerprints

gpg --list-keys


/home/username/.gnupg/pubring.kbx
----------------------------------
pub   rsa4096 2020-02-22 [SC]
      123CB55F1237F1237123456789D12AC123E15123
uid           [ultimate] CodyLane <xxxxxxxx@example.com>
sub   rsa4096 2020-02-22 [E]

  • Next we set GPG_KEY_ID

GPG_KEY_ID=123CB55F1237F1237123456789D12AC123E15123 ./gpg-sae encrypt encrypt_this_file

OR

GPG_KEY_ID=CodyLane ./gpg-sae encrypt encrypt_this_file

  • Next we verify the original file has been deleted, and we have a new encrypted file

ls -l encrypt_this_file*

-rw-r--r-- 1 x 7 1747 Feb 22 00:00 encrypt_this_file.asc

cat encrypt_this_file

-----BEGIN PGP MESSAGE-----

hQIMAyGuJ0m4OrsUARAAmTLm3mVIDO/iG5hkY+S/TtdzpgspzfkR+4vOeZw76mmW
4k6JyQ7r2PlZY/mCHwIrw+b+CfL3FGeJ5INzatXH7y+6pOgOoFJ6a7Wjwog2yN85
Q0+J6gZ9fc0e9XLLRoIKOC7rC9S7WuHIsnpGzG8ZrdEzbpYmR+miaAlfCnXFOrlc
+qsn3H3YT1CtIOs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mg79pRyKX
BNWxtfBFrnRNvPop0iZjZYtDEN4H1Uc+9tXcU4ljtgB7a1GpYr8OcZ1X7EsfhQRb
CUhRL8cTmrU5+m+1xcV7QsECbl611PGeyW+c99kN2fK2wAlSxjpd6XTY84WQxIIE
HHQVqooqP+cnndvakaNqHkFCtzepAoSu3gMwOIl2ZliWbqfu5skZMgC9fvVgemSc
n1lmdvsSTc0IfcrvtZszbytgg5iM4SEMfZhEdeJpu56Ag4Zv7GvJdapZpQv6ugXR
JPhC77/Xbgfc1nvhFK7FVwPwHl6q4pXQDMaLvNWSxkfUECvO/4vDSXe1SPoLW+gb
EK/udCjcRyaHADin8r1fdSaN+V2lP72Jbgx5yALotyYOz9As9p5l9oSTurE=
=GOQf
-----END PGP MESSAGE-----

Decrypting a file


GPG_KEY_ID=CodyLane ./gpg-sae decrypt encrypt_this_file.asc

┌────────────────────────────────────────────────────────────────┐
│ Please enter the passphrase to unlock the OpenPGP secret key:  │
│ "CodyLane <xxxxxxxxx@example.com>"                             │
│ 4096-bit RSA key, ID 123CB55F1237F123                          │
│ created 2020-02-22 (main key ID xxxxxxxxxxxxxxxx).             │
│                                                                │
│ Passphrase: *************************************___________   │
│                                                                │
│         <OK>                                    <Cancel>       │
└────────────────────────────────────────────────────────────────┘

  • Next we validate the file is no longer encrypted

ls -l encrypt_this_file*

-rw-r--r-- 1 x y 53   Feb 20 00:00 encrypt_this_file
-rw-r--r-- 1 x y 1747 Feb 20 00:00 encrypt_this_file.asc
  • And we can finally validate our original contents

cat encrypt_this_file

this is my special file that I would like to encrypt

Author

  • Cody Lane 2020

Releases

No releases published

Packages

No packages published

Languages