Re: Using openssl bf encryption
- -----BEGIN PGP SIGNED MESSAGE-----
On 31-Aug-06, at 12:09 PM, Brian McKee wrote:
> Hi All
> I'd like to be able to edit an encrypted plain text file using vim.
> It's blowfish encoded with openssl.
Well, the response to the previous email was underwhelming :-)
I've done some limited testing, and came up with an addition to
that seems to work really slick. I've attached that to the bottom
for future generations
The nifty unintended side effect was I can encrypt any file I'm
working on just
by saving it with a .bf extension.
If anyone has any comments or spots an ooppsie, by all means let me
" Transparent editing of bf encrypted files.
" Originally By Wouter Hanegraaff <wouter@...>
" with very minor alterations for bf by bmckee <brian.mckee@...>
" note the file must be encrypted with the -a and -salt options
" no guarantees using this won't post your secrets on myspace.com :-)
" First make sure nothing is written to ~/.viminfo while editing
" an encrypted file.
autocmd BufReadPre,FileReadPre *.bf set viminfo=
" We don't want a swap file, as it writes unencrypted data to disk
autocmd BufReadPre,FileReadPre *.bf set nobackup
" We don't want a backup
autocmd BufReadPre,FileReadPre *.bf set nowritebackup
" We don't want an inprogress backup either
autocmd BufReadPre,FileReadPre *.bf set noswapfile
" Switch to binary mode to read the encrypted file
autocmd BufReadPre,FileReadPre *.bf set bin
autocmd BufReadPre,FileReadPre *.bf let ch_save = &ch|set ch=2
autocmd BufReadPost,FileReadPost *.bf '[,']!openssl bf -d -
salt -a 2> /dev/null
" Switch to normal mode for editing
autocmd BufReadPost,FileReadPost *.bf set nobin
autocmd BufReadPost,FileReadPost *.bf let &ch = ch_save|unlet
autocmd BufReadPost,FileReadPost *.bf execute ":doautocmd
BufReadPost " . expand("%:r")
" Convert all text to encrypted text before writing
autocmd BufWritePre,FileWritePre *.bf '[,']!openssl enc -bf
- -salt -a 2>/dev/null
" Undo the encryption so we are back in the normal text, directly
" after the file has been written.
autocmd BufWritePost,FileWritePost *.bf u
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
-----END PGP SIGNATURE-----