GPG: Password Encryption

Encrypt a file

echo 'hello' > hello.txt

gpg -c hello.txt
# OR
gpg --symetric hello.txt

Enter the prompted password.

After that, it will generate a file named hello.txt.gpg.

Decrypt a file

gpg hello.txt.gpg
# OR
gpg -d hello.txt.gpg
# OR
gpg --decrypt hello.txt.gpg

Non-interactive

# Plain text
gpg --batch --passphrase 'mypasswd' -c hello.txt

# File descriptor stdout
echo 'mypasswd' | gpg --batch --passphrase-fd 0 -c hello.txt

# File descriptor stdin
gpg --batch --passphrase-fd 1 -c hello.txt
#type your string here and end with ^D^D (2x Ctrl-D)

# Content of a file
gpg --batch --passphrase-file ./myfile.txt -c hello.txt

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *