-
Notifications
You must be signed in to change notification settings - Fork 0
/
gem
executable file
·48 lines (33 loc) · 1.38 KB
/
gem
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
40
41
42
43
44
45
46
47
48
#!/home/dd/anaconda3/bin/python
"""GnuPG encryption module. (github.com/taext/gem)"""
######################################################
# #
# gem v3.0 (July 23rd 2017) #
# #
# What's New: Updated gh address to new name (3) #
# #
# #
######################################################
import gnupg
import sys
def main(clear_text,
pubkey_file_name='pubkey.asc',
pubkey_file_path='/home/dd/Documents/pubkeys/'):
"""Takes clear text string, optionally pubkey filename
and file path, returns PGP-encrypted string."""
gpg = gnupg.GPG()
key_data = open(pubkey_file_path + pubkey_file_name).read()
import_result = gpg.import_keys(key_data)
fingerprint = import_result.results[0]['fingerprint']
encr_data = gpg.encrypt(clear_text, fingerprint)
result = str(encr_data)
return result
if __name__ == '__main__':
if len(sys.argv) == 1: # no arguments, piping mode
args = sys.stdin.read() # if no piped input,
print(main(args)) # reads from keyboard
else:
args = []
[args.append(item) for item in sys.argv[1:]]
if args:
print(main(*args))