-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt.py
More file actions
38 lines (27 loc) · 956 Bytes
/
decrypt.py
File metadata and controls
38 lines (27 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import subprocess
import sys
import pgpy
from pywell.entry_points import run_from_cli
DESCRIPTION = 'Decrypt PGP files with GPG.'
ARG_DEFINITIONS = {
'BASE_DIRECTORY': 'Path to where files are located.',
'FILE': 'File to decrypt.',
'PGP_KEY': 'Full key for PGP',
'PGP_PASS': 'Pass phrase for PGP'
}
REQUIRED_ARGS = [
'BASE_DIRECTORY', 'FILE', 'PGP_KEY', 'PGP_PASS'
]
def main(args):
message = pgpy.PGPMessage.from_file('%s%s' % (args.BASE_DIRECTORY, args.FILE))
private_key, _ = pgpy.PGPKey.from_blob(args.PGP_KEY)
with private_key.unlock(args.PGP_PASS):
csv = private_key.decrypt(message).message.decode("utf-8")
new_file_name = '.'.join(args.FILE.split('.')[:-1])
file = open("%s%s" % (args.BASE_DIRECTORY, new_file_name), "w")
file.write(csv)
file.close()
return new_file_name
if __name__ == '__main__':
run_from_cli(main, DESCRIPTION, ARG_DEFINITIONS, REQUIRED_ARGS)