Function: org-encrypt-entry
org-encrypt-entry is an autoloaded, interactive and byte-compiled
function defined in org-crypt.el.gz.
Signature
(org-encrypt-entry)
Documentation
Encrypt the content of the current headline.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-crypt.el.gz
;;;###autoload
(defun org-encrypt-entry ()
"Encrypt the content of the current headline."
(interactive)
(unless (org-at-encrypted-entry-p)
(require 'epg)
(setq-local epg-context (epg-make-context nil t t))
(org-with-wide-buffer
(org-back-to-heading t)
(let ((start-heading (point))
(crypt-key (org-crypt-key-for-heading))
(folded? (org-invisible-p (line-beginning-position))))
(org-end-of-meta-data 'standard)
(let ((beg (point))
(folded-heading
(and folded?
(save-excursion
(org-previous-visible-heading 1)
(point)))))
(goto-char start-heading)
(org-end-of-subtree t t)
(org-back-over-empty-lines)
(let* ((contents (delete-and-extract-region beg (point)))
(key (get-text-property 0 'org-crypt-key contents))
(checksum (get-text-property 0 'org-crypt-checksum contents)))
(condition-case err
(insert
;; Text and key have to be identical, otherwise we
;; re-crypt.
(if (and (equal crypt-key key)
(string= checksum (sha1 contents)))
(get-text-property 0 'org-crypt-text contents)
(epg-encrypt-string epg-context contents crypt-key)))
;; If encryption failed, make sure to insert back entry
;; contents in the buffer.
(error
(insert contents)
(error "%s" (error-message-string err)))))
(when folded-heading
(goto-char folded-heading)
(org-fold-subtree t))
nil)))))