2009-12-14

Encrypt your important data in Emacs org-mode

Emacs org-mode is an awesome tool to help me manage your personal information. The beauty of it derives from its pure-text-file nature. And the ugly thing, well, also derives from its pure-text-file nature - Security issue. Every bit of your data could be seen if you don't carefully keep them safe.

But, don't panic first. Emacs 23 and org-mode have provided things to secure your data. Normally, I put my very personal data in a separated file and you can make Emacs encrypt it automatically when saving it. All you need to do is to
  1. Load EasyPG in your environment.
    (require 'epa)
    (epa-file-enable)
    
  2. Rename your personal file with .gpg as its extension
  3. Add the following lines to the beginning of the personal file
    -*- mode: org; epa-file-encrypt-to: ("yenliangl@gmail.com") -*-
When you save this file, Emacs will gpg-encrypt this file. And when you load this file back, it prompts you to enter your GPG key.


Second, what if you don't encrypt the whole file? You merely want some header sections encrypted. That's ok. The org-mode provides another module to do this for you - org-crypt. Here is my settings,
(require 'org-crypt) 
(org-crypt-use-before-save-magic)
(setq org-tags-exclude-from-inheritance (quote ("crypt")))
(setq org-crypt-key "0C6F5345") ;; yenliangl@gmail.com
The header sections with tag crypt are encrypted when you save the file. If you don't like this tag, go on to check out org-crypt.el for command to change it.


Note that if you encrypt the whole file, its content won't appear in the agenda view. But, encrypting a header section won't exclude itself from agenda view as long as you put time settings on the header not in its content because its content is encrypted.