]
Vim never fails to surprise you with the amazing features it has in its arsenal. Very recently I have found that Vim comes bundled with an encryption mechanism referred to as VimCrypt.
It is always a good practice to encrypt your files especially when it contains personal or sensitive information. I often write my Daily journal notes in vim and i always encrypt them with some external programs. But, Vim itself is capable of doing that.
Let's see how it works.
Here, I have a file named encrypt.txt open in vim.
So, now I want to encrypt this. All I have to do is this and press Enter.
:X
And, it will prompt you to enter a key for the Encryption. Enter it twice. This will be used to encrypt and later decrypt the file
And, that is all.. Your file is now encrypted with the key you have given.
The next time you try to open the file again, it will prompt you to enter the Encryption key.
Make sure to remember the key you have entered because if you enter a wrong key to decrypt the data, you will see a completely garbled gibberish on screen.
So, that is how you encrypt your files in Vim.
But, here are a few things to be mindful of
- VimCrypt uses a really weak encryption algorithm. It can be broken rather effortlessly. Hence ,don't use this for encrypting really really important files.
- If you open the file with a wrong password, you'll see garbled text on screen. But, Do not save that gibberish file on to the disc, because if you do, Vim will overwrite your original file contents and your data will be lost.
There are several new encryption methods available to achieve the same thing like, Blowfish and Blowfish 2. These are much better than the default VimCrypt and will be much harder to crack. More about them later in another tutorial.
So, that is all for this article. Its good practice to encrypt files to keep your data secure. So, try to use this whenever you can.
And, until next time, happy Vimming!