Search code examples
encryptionemacsorg-modegnupg

How to encrypt individual headings in org-mode?


I have searched everywhere for information on how to use org-crypt to password protect specific headings in org-mode. Most of the info out there says use org-crypt. I have added the org-crypt lines to my .emacs without any luck getting it to work. I think you also have to use gpg but am still unsure.

I have added:

(require 'org-crypt)
(org-crypt-use-before-save-magic)
(setq org-tags-exclude-from-inheritance (quote ("crypt"))) 
;;  set to nil to use symmetric encryption.
(setq org-crypt-key nil)

When I save the file with the crypt tag nothing happens. I think I am missing some kind of connecting code. Anyone know what I am doing wrong? Many Thanks in advance.


Solution

  • Much internet searching and trial (lots of error) led me to the config below. Essentially you use org-crypt WITH gnupg. Keep in mind I am running macOS Sierra and Emacs 25.2 .

    Use homebrew to install gnupg: brew install gnupg2

    Add the following lines to your .emacs. It will allow you to encrypt individual headings in an org-file with a passphrase using the TAG :crypt: when added to the heading and saved (C-x C-s). Upon save there will be a pop-up asking for the passphrase.

    (require 'epa-file)
    (custom-set-variables '(epg-gpg-program  "/usr/local/bin/gpg2"))
    (epa-file-enable)
    
    (require 'org-crypt)
    (org-crypt-use-before-save-magic)
    (setq org-tags-exclude-from-inheritance (quote ("crypt"))) 
    ;;  set to nil to use symmetric encryption.
    (setq org-crypt-key nil)
    

    For good measure:

    ;; Global Tags
    (setq org-tag-alist '(("crypt" . ?c))) 
    

    That should be it. Hope this helps.