Modifying vim to support encrypted files — goCrypt

Harshit Sharma
3 min readMay 22, 2020

There is a common use case where people need an editor that can use a certain key to encrypt their files while saving and while editing it can display the encrypted file in plain text.

Although vim has certain extensions to accomplish this but those make this process a bit too complicated.

So here we will use our basic terminal editor vim and layer it up with our code to make it satisfy our use case while still keeping the approach simple.

Usage

Step1: Writing/Editing a file

$ goCrypt -w /path/to/file -k encryptionKey

this opens up vim and allows you to enter your data as regular plain text

after simply saving this, you will get an output stating that your file has been saved.

Step2: Reading a file

$ goCrypt -r /path/to/file -k encryptionKey

this will produce an output like

Now, if the encryption key here is not same as it was while writing the file then it will produce an error

Authentication failed error

Lets now see what is actually there in the file if we directly try to see it without goCrypt

$ cat /path/to/file

This is what you get.

Implementation

Raw usage

$ git clone https://github.com/sharma1612harshit/goCrypt
$ cd goCrypt
$ go run main.go [options]

Binaries

$ git clone https://github.com/sharma1612harshit/goCrypt -b v1.0.0-binariesHere the directories are of the form (os-architecture)
choose your os and architecture and use the precompiled binary

Options and Functionalities

Usage: gocrypt [option] [supporting options]

Options:
1) -w (write a file): gocrypt -w filename [optional arguments]
2) -r (read a encrypted file): gocrypt -r filename [optional arguments]
3) -h (help): gocrypt -h

Optional Arguments:
1) -k (encryption key):
gocrypt -w filename -k encryption_key
gocrypt -r filename -k encryption_key
if -k is not provided then the default key is used

--

--