amuck-landowner

Encrypt Files With Vim

raindog308

vpsBoard Premium Member
Moderator
One of those "I never knew it could do this" things.
 
Starting vim with the -x flag will prompt you for an encryption key.  After you enter it twice, vim will encrypt the file.  If you later vim the file, vim will discover the file is encrypted (because a magic is prepended) and prompt for the key.
 
Vim does the right thing in terms of also encrypting the .swp file.  However, there are some caveats/details
 
By default, vim uses the 'zip' algorithm which is extremely insecure.  However,


set cm=blowfish

in your .vimrc will force it to use blowfish.
 
Also, your .viminfo may leak text you copy/delete.  At a minimum you need to turn off registers.  I would probably create an alias or a small shell script that verifies the correct cm= line is in .vimrc and sets the registers (see this).  e.g., a script called 'vie' that does that and then invokes vim. 
 
Finally, the vim folks don't appear to be very confidant in their crypto:


The encryption in Vim has not been tested for robustness.
For more details, see this part of the vim docs.
 

coreyman

Active Member
Verified Provider
Very nice, but very small use case! There are a lot of other encryption techniques that are already used that cover a wider base of files than just readable text - like entire file system encryption.
 

SentinelTower

New Member
This is a nice trick to know but I prefer using GnuGP for encrypting things when I need too.

Also some people are a bit reluctant when it comes to vim, they do not understand how powerful it is and prefer the nano or emacs way, so it restricts a bit the shareability of your file.
 

raindog308

vpsBoard Premium Member
Moderator
There's actually a gnupg plugin for vim, though I haven't played with it yet.

You have a good point - what's written by encrypted vim is somewhat vim-specific.  The algorithm (such as blowfish) is open but the specific file format is vim-specific.
 
Top
amuck-landowner