Search

Encrypting text files using VI editor

While creating text files using the "vi" editor we can make the files secure by encrypting the files with our own encryption key. Any encrypted file will be unreadable unless the coorect key is not known.

Let us say we have a file by the name temp:



To encrypt this file, so that no one with out the encryption keys is able to read or write from the file, open the file using vi editor



Now go to command mode by typing "esc"

Then type :X and press enter.



Note the "X" is in upper case

VI will now prompt for an encryption key as shown below.



Enter any key, and press enter

It will prompt for confirmation of the key, enter the same key again .



To find out whether the file is encrypted or not we can use the command file



Thus indicating that it is an encrypted file. If we try to read from the file using cat





The output will be junk value. If we try to open the file using "vi" editor, it will prompt us for the encryption key.

In case we entered the wrong key, the file will open but with garbage values in it, and it will be in read only mode.



Only on entering the correct key, the file be visible in the original form

To remove the encryption, open the file using "vi" editor by entering the correct key and go to the command mode. Use the command





And press enter. It will prompt for a value of key, hit enter, do not enter any value for the key.



The encryption should have been removed now and we can edit the file as usual way.

No comments:

Post a Comment