Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sni/govimcrypt
Decrypt / Encrypt VimCrypted data (blowfish2 only)
https://github.com/sni/govimcrypt
Last synced: about 2 months ago
JSON representation
Decrypt / Encrypt VimCrypted data (blowfish2 only)
- Host: GitHub
- URL: https://github.com/sni/govimcrypt
- Owner: sni
- License: mit
- Created: 2021-06-14T19:41:48.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-03-14T12:44:34.000Z (9 months ago)
- Last Synced: 2024-05-21T12:23:42.093Z (7 months ago)
- Language: Go
- Size: 270 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go VimCrypt
Package vimcrypt implements reading and writing of vim encrypted files with golang.
Supports blowfish2 only, since this is the recommended vim cryptmethod.
## Using VIM
### Create
To create a new encrypted file, run:
%> vim -x /tmp/testfile.txt
Enter the new password twice.
In vim, set the cryptmethod with:
:set cm=blowfish2
Enter some text (the file must not be empty) and save the file:
:x!
Verify the file is encrypted properly:
%> file /tmp/testfile.txt
/tmp/testfile.txt: Vim encrypted file data with blowfish2 cryptmethod### Read
To read the file with vim again, you don't need to specify -x again:
%> vim /tmp/testfile.txt
## Usage
### Reading
```golang
import (
vimcrypt "github.com/sni/govimcrypt"
)password := []byte("secret")
file := "/tmp/testfile.txt"
fh, err := os.Open(file)
r := bufio.NewReader(fh)
vc, err := vimcrypt.NewReader(r, password)
decrypted := new(strings.Builder)
io.Copy(decrypted, vc)
fmt.Printf("decrypted content is: %s", decrypted.String())
```### Writing
```golang
import (
vimcrypt "github.com/sni/govimcrypt"
)password := []byte("secret")
file := "/tmp/testfile.txt"
encrypted := bytes.NewBuffer(nil)
vc, err := vimcrypt.NewWriter(encrypted, password)
vc.Write([]byte("...clear text"))
ioutil.WriteFile(file, encrypted.Bytes(), 0644)
```