Reputation: 85462
In my Python web app, I would need to decrypt a file that was encrypted using VIM. Assuming the web app knows the password used to encrypt the file in VIM, how do I write code to decrypt ?
Upvotes: 3
Views: 2356
Reputation: 4655
The python3 version:
from pathlib import Path
from zipfile import _ZipDecrypter
print(_ZipDecrypter(b"<password>")(Path(r"<path>").read_bytes()[12:]).decode("utf8"))
Upvotes: 0
Reputation: 2776
I wrote a tool to do exactly that, also supporting the more recent encryption methods:
https://github.com/nlitsme/vimdecrypt
Upvotes: 1
Reputation: 799200
Turns out that vim uses the same encryption as PKZIP:
from zipfile import _ZipDecrypter
fp = open(somefile, 'rb')
zd = _ZipDecrypter(somekey)
fp.read(12)
print ''.join(zd(c) for c in fp.read())
fp.close()
Upvotes: 7