How to use gpg to encrypt from STDIN using a symmetric cipher?

1

1

I'm trying to encrypt data from STDIN using gpg. I'm using the following:

echo 'plaintext' | gpg -c -o output.gpg

However, I see the following result:

gpg: problem with the agent: Inappropriate ioctl for device
gpg: error creating passphrase: Operation cancelled
gpg: symmetric encryption of '[stdin]' failed: Operation cancelled

How would I encrypt from STDIN using gpg and a symmetric cipher only? I am on MacOS and GPG v2.2.13.

wcarhart

Posted 2019-02-26T05:27:58.217

Reputation: 113

Can not reproduce on arch linux with GnuPG 2.2.12. Can you tell us which --version of gpg you are using? – confetti – 2019-02-26T05:51:55.673

@confetti I'm using MacOS, if that makes a difference. GPG v2.2.13, updated the question – wcarhart – 2019-02-26T06:09:09.500

Answers

1

It is a problem with pinentry (utility used to register the passphrase). Is it installed on your mac? If not, run brew install pinentry-mac and try again, otherwise you need to change your configuration. Check the comment on this issue for details but this should be ok:

brew install pinentry-mac
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

Dorsug

Posted 2019-02-26T05:27:58.217

Reputation: 26

2

Many people recommend installing pinentry-mac, a package that isn’t maintained by the official GnuPG team. I would recommend against it.

A more secure alternative is to append the following lines to ~/.profile as suggested in the official docs (appending them to ~/.bashrc didn’t work for me).

GPG_TTY=$(tty)
export GPG_TTY

Once these lines have been appended, close your terminal and the issue should be resolved.

Also, make sure you upgrade gnupg to the latest version using brew upgrade gnupg.

sunknudsen

Posted 2019-02-26T05:27:58.217

Reputation: 269