Vim encrypted file

Source: Internet
Author: User
Recently, I tried to use vim in Windows. after you download gvim and install it, you can use gvim to write text files and encrypt them to prevent others from seeing the text content easily. To prevent Chinese garbled characters, find the _ vimrc File (for example, C: \ ProgramFiles \ Vim \ _ vimrc) and add the following code at the end of the File :...

 

Recently, I tried to use vim in Windows. after you download gvim and install it, you can use gvim to write text files and encrypt them to prevent others from seeing the text content easily.

To prevent Chinese garbled characters, find the _ vimrc File (for example, "C: \ Program Files \ Vim \ _ vimrc") and add the following code at the end of the file: Txt code

Set fileencodings = UTF-8, gb2312, gbk, gb18030

 

Set termencoding = UTF-8

 

Set fileformats = unix

 

Set encoding = prc

 

Set fileencodings = UTF-8, gb2312, gbk, gb18030

 

Set termencoding = UTF-8

 

Set fileformats = unix

 

Set encoding = prc

 

 

 

Note that in Windows 7 and vista, you can use vim to open the vimrc file directly due to the administrator privilege of the enhanced version, and the modifications you have made cannot be saved! Even if you are using wq! Command! A simple method is to start vim with the administrator privilege in the beginning, and then use vim to open the vimrc file for modification!

After completing the preceding operations, you can encrypt the file and enter the file to be encrypted,

After editing the file, press ESC to return to the command mode and enter ": X"

You are prompted to confirm a password for file encryption and decryption:

 

Enter encryption key:

 

Enter the password carefully. The character you typed will be replaced by an asterisk, so you cannot see it. To avoid

Typing errors cause trouble. Vim requires you to enter the password again:

 

Enter same key again:

 

Now you can edit this file and put all your secrets in it as usual

Enter w to save the file, and then enter the password to access the file later. if you use another text editing tool to forcibly open the encrypted file, you will find that the text is garbled.

To remove the password, follow these steps:

Cmd code

Vim file

 

Enter encryption key: Enter the password

 

: Set key =

 

: W!

 

Vim file

 

Enter encryption key: Enter the password

 

: Set key =

 

: W!

 

Resolution limitations

 

The encryption algorithm used by Vim has weaknesses. It is more than enough to prevent hackers, but it is not enough to prevent a password expert who has a lot of time. Moreover, you should know that the swap file is not encrypted. Therefore, when you edit the file, people with super user permissions can read unencrypted file text. One way to prevent people from reading your swap files is to not use swap files.

: Setlocal noswapfile

File restoration is impossible without file exchange. In order to avoid losing the edited results, it is more diligent than usual.

Save your files.

Batch encryption in vim

Shell code

#! /Bin/bash

# Encrypt file with vim

 

If (test $ #-lt 2) then

Echo Usage: decrypt password filename

Else

Vim-e-s-c ": set key = $1"-C': wq' $2

Echo "$2 encrypted ."

Fi

 

#! /Bin/bash

# Encrypt file with vim

 

If (test $ #-lt 2) then

Echo Usage: decrypt password filename

Else

Vim-e-s-c ": set key = $1"-C': wq' $2

Echo "$2 encrypted ."

Fi

 

References:

Http://hi.baidu.com/%C1%EE%BA%FC%D2%BB%B6%FE/blog/item/a29be2eb8d7790d9d539c990.html

Http://www.2cto.com/ OS /201111/110621.html,

Http://www.2cto.com/ OS /201111/110622.html

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.