9

I have an accounts.org.gpg file. I can open it using gpg directly:

$ gpg -d ./accounts.org.gpg 

You need a passphrase to unlock the secret key for
user: "Omair Majid <removed@removed>"
4096-bit RSA key, ID 7CC8AAC6, created 2012-01-18 (main key ID 66484681)

gpg: encrypted with 4096-bit RSA key, ID 7CC8AAC6, created 2012-01-18
    "Omair Majid <removed@removed>"
+TITLE: Accounts
<rest of output removed>

But I can't open the same file using Emacs. Trying to open it in emacs gives me an error:

epa-file--find-file-not-found-function: Opening input file: Decryption failed, No secret key: E295ECEC7CC8AAC6

Is there something I need to configure on the emacs side to make this work?

For some additional background, I created this file on another machine (using the same version of Emacs), on which Emacs could read/write to that file just fine. I then copied over the contents of ~/.gnupg over to this machine. And now gpg can still read it, but Emacs can't.

EDIT: Could this be a gpg1 vs gpg2 difference?

$ gpg2 --decrypt accounts.org.gpg 
gpg: encrypted with RSA key, ID E295ECEC7CC8AAC6
gpg: decryption failed: No secret key

How was the Emacs on the other machine (using same configuration, same version of Emacs (25.1) and same OS (Fedora 24 x86_64, same version of gpg and gpg2 packages)) read from it and write to it. Anyway using,

(setq epg-gpg-program "/usr/bin/gpg")

Still results in the same error.

  • Have you tried (setq epg-gpg-program "gpg2") ? – caisah Oct 16 '16 at 7:11
  • I did. It's the default too. And it doesn't work. Just like the gpg2 command line program doesn't. I am starting to think this is a problem with gpg2 itself, not emacs at all. – Omair Majid Oct 16 '16 at 23:04
  • 3
    @caisah See Bug #24229, setq doesn't work for epg-gpg-program, you have to customize it. – npostavs Oct 17 '16 at 16:09
13

You do not say which OS nor version of emacs you have.

I solved yesterday exactly the same problem in OSX and emacs 25.1 using information from this link: http://colinxy.github.io/software-installation/2016/09/24/emacs25-easypg-issue.html

I ran these commands:

brew unlink gnupg2 gpg-agent dirmngr
brew uninstall gnupg2 gpg-agent dirmngr
brew install gnupg21
ln -s /usr/local/bin/gpg2 /usr/local/bin/gpg

and set the pinentry mode in my emacs conf file:

(setf epa-pinentry-mode 'loopback)
  • Please see my edits for OS and Emacs versions. I definitely don't plan to override the system versions of gpg/gpg2. – Omair Majid Oct 17 '16 at 14:51
  • The standard brew package gnupg has for some time now been version 2.1. Older versions 1.4 and 2.0 that are not fully compatible with it are available as separate packages. – Heikki Jul 10 '17 at 19:20
  • Just a info: I had a similar problem on Linux and this solution fixed my problem as well. – Manoel Vilela May 1 '18 at 15:22
  • 1
    Thanks for pointing out the (setf epa-pinentry-mode 'loopback) trick. – phs Mar 11 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.