Suppose you have a cleartext file that you want to encrypt with a password, here's how you do that with
ccrypt on macOS. First:
▶ brew install ccrypt
Now, you have the
ccrypt program. Let's test it:
▶ cat secrets.txt Garage pin: 123456 Favorite kid: bart Wedding ring order no: 98c4de910X ▶ ccrypt secrets.txt Enter encryption key: ▉▉▉▉▉▉▉▉▉▉▉ Enter encryption key: (repeat) ▉▉▉▉▉▉▉▉▉▉▉ # Note that the original 'secrets.txt' is replaced # with the '.cpt' version. ▶ ls | grep secrets secrets.txt.cpt ▶ less secrets.txt.cpt "secrets.txt.cpt" may be a binary file. See it anyway?
There. Now you can back up that file on Dropbox or whatever and not have to worry about anybody being able to open it without your password. To read it again:
▶ ccrypt --decrypt --cat secrets.txt.cpt Enter decryption key: ▉▉▉▉▉▉▉▉▉▉▉ Garage pin: 123456 Favorite kid: bart Wedding ring order no: 98c4de910X ▶ ls | grep secrets secrets.txt.cpt
Or, to edit it you can do these steps:
▶ ccrypt --decrypt secrets.txt.cpt Enter decryption key: ▉▉▉▉▉▉▉▉▉▉▉ ▶ vi secrets.txt ▶ ccrypt secrets.txt Enter encryption key: Enter encryption key: (repeat)
Clunky that you have you extract the file and remember to encrypt it back again. That's where you can use
emacs. Assuming you have
emacs already installed and you have a
~/.emacs file. Add these lines to your
(setq auto-mode-alist (append '(("\\.cpt$" . sensitive-mode)) auto-mode-alist)) (add-hook 'sensitive-mode (lambda () (auto-save-mode nil))) (setq load-path (cons "/usr/local/share/emacs/site-lisp/ccrypt" load-path)) (require 'ps-ccrypt "ps-ccrypt.el")
By the way, how did I know that the load path should be
/usr/local/share/emacs/site-lisp/ccrypt? I looked at the output from
▶ brew info ccrypt ccrypt: stable 1.11 (bottled) Encrypt and decrypt files and streams ... ==> Caveats Emacs Lisp files have been installed to: /usr/local/share/emacs/site-lisp/ccrypt ...
Anyway, now I can use
emacs to open the
secrets.txt.cpt file and it will automatically handle the password stuff:
This is really convenient. Now you can open an encrypted file, type in your password, and it will take care of encrypting it for you when you're done (saving the file).
Be warned! I'm not an expert at either
emacs or encryption so just be careful and if you get nervous take precaution and set aside more time to study this deeper.