;;; epa-file.el --- the EasyPG Assistant hooks for transparent file encryption ;; Copyright (C) 2006 Daiki Ueno ;; Author: Daiki Ueno ;; Keywords: PGP, GnuPG ;; This file is part of EasyPG. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Code: (require 'epa) (defgroup epa-file nil "The EasyPG Assistant hooks for transparent file encryption" :group 'epa) (defcustom epa-file-name-regexp "\\.gpg\\'" "Regexp which matches filenames to be encrypted with GnuPG." :type 'regexp :group 'epa-file) (defvar epa-file nil) (defun epa-find-file () (when (string-match epa-file-name-regexp (buffer-file-name)) (if (= (buffer-size) 0) (progn (set-auto-mode) (hack-local-variables) (auto-save-mode nil)) (goto-char (point-min)) (insert (epg-decrypt-file (epg-make-context) (expand-file-name (buffer-file-name)) nil)) (delete-region (point) (point-max)) (decode-coding-region (point-min) (point-max) 'undecided)) (make-local-variable 'epa-file) (setq epa-file (buffer-file-name)))) (defun epa-write-file () (when epa-file (write-region (epg-encrypt-string (epg-make-context) (buffer-string) (mapcar (lambda (key) (epg-sub-key-id (car (epg-key-sub-key-list key)))) (epa-select-keys "Select recipents for encryption. If no one is selected, symmetric encryption will be performed. "))) nil (expand-file-name (buffer-file-name))) (set-buffer-modified-p nil) t)) (provide 'epa-file) ;;; epa-file.el ends here