Vim has an-X option that allows you to encrypt files when you create them. Once you run the following VIM command, you will be prompted to enter a key:
$ vim-x file.txt Warning: Weak encryption method is being used; see: Help ' cm ' Input encryption key: ******* Enter the same key again: *******
If you enter the key correctly for the second time, you can modify the file.
650) this.width=650; "title=" "src=" Http://s2.51cto.com/wyfs02/M01/97/91/wKioL1kvxFWQzAQ2AAAc5ziU1zE271.png " border= "0"/>
Password-protected Vim files
When you're done, press ESC and type: Wq to save and close the file. Next time you want to open it and edit it, you have to enter the key like this:
$ vim file.txt requires "file.txt" encryption key warning: Weak encryption method is being used; see: Help ' cm ' input key: *******
Suppose you lose a wrong password (or you don't lose the password), you'll see some junk characters.
650) this.width=650; "title=" "src=" Http://s3.51cto.com/wyfs02/M01/97/90/wKiom1kvxH-j0s_TAAAnrLYZ5DM014.png " border= "0"/>
Encrypted content in Vim
Setting a strong encryption method in Vim
Note: The warning message implies that the protected file is a weak encryption method. So next, let's look at how to set up a strong encryption method in Vim.
650) this.width=650; "title=" Vim file weak encryption "alt=" Vim file weak encryption "src=" http://s4.51cto.com/wyfs02/M02/97/91/ Wkiol1kvxnmsip5jaaafipj0xok388.png "border=" 0 "/>
Weak file encryption in Vim
In order to view the encryption method (cm) set, type the following:
: Help ' cm '
Sample output:
* ' cryptmethod ' * * ' cm ' * thod ' string (default "Zip") Global or local to buffer |global-local| {not in Vi} the encryption method used when the buffer is written into the file: *pkzip* zip PkZip compatibility mode. a weak encryption method. is compatible with Vim 7.2 and older versions. *blowfish* blowfish Blowfish encryption method. Intermediate Strength encryption method But there is implementation on 's flaws. Requires Vim 7.3 and above, the file encrypted with it does not can be read by Vim 7.2 and older versions. It will add a "seed", each time you write to a file, this encrypted byte is different.
You can set a new encryption method for a Vim file as shown below (in this case we use the Blowfish2 encryption method)
: setlocal CM=BLOWFISH2
Then type enter and: Wq to save the file.
650) this.width=650; "title=" set strong encryption for vim files "alt=" set strong Encryption "src=" for vim files Http://s5.51cto.com/wyfs02/M00/97/90/wKiom1kvxR_ Ayy2paaadac9lr-i740.png "border=" 0 "/>
Setting strong encryption on Vim files
Now you should not be able to see the warning message when you open the following file again.
$ vim file.txt requires "file.txt" encryption key input encryption key: *******
You can also set a password after you open the Vim file, using the: X command to set an encryption password as shown above.
This article is from the "high-tech Library" blog, please be sure to keep this source http://gaopengju.blog.51cto.com/12830710/1947393
How to use Vim to password protect files in Linux