Two handy GPG tricks

github logo ・1 min read

If you've ever needed to generate random passwords and you have gpg installed then you can just run

gpg --gen-random 0 64 | shasum -a 512 -b |  head -c 32

You can save the generated password to a file and then use --passphrase-file to encrypt a file with it

gpg --gen-random 0 64 | shasum -a 512 -b |  head -c 32 > password
gpg --batch --no-tty --cipher-algo AES256 --output input.gpg \
  --passphrase-file password --symmetric input

You can also do it all in one go with file descriptor substitution

gpg --batch --no-tty --cipher-algo AES256 --output input.gpg \
  --passphrase-file <(gpg --gen-random 0 64 | shasum -a 512 -b | \
    head -c 32 | tee password) --symmetric input
twitter logo DISCUSS
Classic DEV Post from Dec 2 '18

What are your programming goals for 2019?

Share your programming goals for next year!

david karapetyan profile image
Dispassionate problem solver. I enjoy building minimal and efficient systems. I like to think I don't drink the kool-aid