How to use Emacs to recognize and automatically open GPG encrypted file in ASCII armored format?

Everything should work fine with the default configuration, but you can check your configuration.

First, you need to be sure that EasyPG Assistant is installed.

M-xlocate-libraryRETepaRET should return something like:

Library is file /usr/local/share/emacs/24.2.50/lisp/epa.elc

If not, then you've to install it. (or upgrade to Emacs23 or Emacs24)

  1. http://emacswiki.org/emacs/EasyPG
  2. http://epg.sourceforge.jp/

Then, check the value of the variable auto-mode-alist with C-hvauto-mode-alistRET and search for epa.

If you cannot find it, add this snippet to your .emacs.

(add-to-list 'auto-mode-alist '("\\.gpg\\(~\\|\\.~[0-9]+~\\)?\\'" nil epa-file))

I had the same issue as the original poster. I want EasyPG to save files with a .asc extension in ASCII-armored ciphertext, not binary. There's some good info in the responses, but none was complete enough to solve the OP's issue. I think I solved it with the following configuration.

(epa-file-enable)

(setq epa-file-name-regexp "\\.\\(gpg\\|\\asc\\)\\(~\\|\\.~[0-9]+~\\)?\\'")
(epa-file-name-regexp-update)

;; Minor mode for ASCII-armored gpg-encrypted files
(define-minor-mode auto-encryption-armored-mode
  "Save files in encrypted, ASCII-armored format"
  ;; The initial value.
  nil
  ;; The indicator for the mode line.
  " Encrypted,Armored"
  ;; The minor mode bindings.
  nil
  (if (symbol-value auto-encryption-armored-mode)
      (set (make-local-variable 'epa-armor) t)
    (kill-local-variable 'epa-armor))
  )

(add-to-list 'auto-mode-alist '("\\.asc$" . auto-encryption-armored-mode))

First, this adds .asc and Emacs backup names to the file name extensions that EasyPG will save as encrypted data, by default binary.

Then it defines a minor mode that sets epa-armor as a buffer local variable. Inspired by sensitive-mode: http://anirudhsasikumar.net/blog/2005.01.21.html

Finally, it sets that minor mode to automatically activate when opening .asc files. TODO: Also activate when opening Emacs backup files.

Note that the "extra" epa-file-name-regexp regexp syntax is critical if you don't want cleartext copies of your .gpg and .asc files floating around as Emacs backups.

Seems to work OK so far.

This question is pretty stale, but there's also not an easy solution shipped with EasyPG and Emacs 24 on Debian 8.3. Hope that helps.


I did following to let Emacs open .asc files in the same way of .gpg files

(require 'epa-file)
(epa-file-enable)
(setq epa-file-name-regexp "\\.\\(gpg\\|asc\\)$")
(epa-file-name-regexp-update)