In this howto we will see how to encrypt and decrypt a file with Vim editor.
Lets Encrypt a file:
linux-06ac:/opt # vim -x encryptedfile.txt Warning: Using a weak encryption method; see :help 'cm' Press ENTER or type command to continue
Now Press enter and it will ask you to set a password.
Enter encryption key: ********** Enter same key again: **********
Once you setup the password, you will be presented with the blank page where you can start writing to the file as you do with Vim.
I am writing ” Helo Linux World” as an example to my encryptedfile.txt , save and quit with :wq
Not cat the file
linux-06ac:/opt # cat encryptedfile.txt VimCrypt~01!q"[�HY�&!���+B]3linux-06ac:/opt #
We can see that the file is Encrypted.
Decrypt the File:
To Decrypt permanently, open the file as following:
linux-06ac:/opt # vim encryptedfile.txt
Give the password to the file , you set while encrypting it.
Then type :X and press enter twice (without typing anything) when asked for “Enter encryption key:”
Now save and exit with :wq and viola the file is decrypted.
linux-06ac:/opt # cat encryptedfile.txt Helo Linux World
Thanks & Regards,
Salman A. Francis