-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt_file.py
More file actions
executable file
·39 lines (34 loc) · 955 Bytes
/
decrypt_file.py
File metadata and controls
executable file
·39 lines (34 loc) · 955 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
39
#!/usr/bin/env python
import os
import gnupg
import sys
import getpass
#
# Script to decrypt the backed up files
# @author rahulsh1
#
# Decrypts the file using the given password
def decrypt(password, gpg_file):
print("Decrypting " + gpg_file + "...")
gpg_home = os.getenv("HOME") + "/.gpghome"
gpg = gnupg.GPG(gnupghome=gpg_home)
dest_file = os.path.splitext(gpg_file)[0]
with open(gpg_file, 'rb') as f:
status = gpg.decrypt_file(
file=f,
passphrase=password,
output=dest_file)
print('decryption ok: ', status.ok)
#print('decryption status: ', status.status)
#print('decryption stderr: ', status.stderr)
print('~'*50)
def main():
args = sys.argv[1:]
if not args:
print("usage: " + sys.argv[0] + " <file>");
sys.exit(1)
file = sys.argv[1]
passphrase = getpass.getpass()
decrypt(passphrase, file)
if __name__ == '__main__':
main()