-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgem
76 lines (58 loc) · 3.3 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/home/dd/anaconda3/bin/python
""" GPG encryption to default pubkey.
(https://github.com/taext/gem-and-cle/blob/master/gem) """
_____ _____ _____
/\ \ /\ \ /\ \
/::\ \ /::\ \ /::\____\
/::::\ \ /::::\ \ /::::| |
/::::::\ \ /::::::\ \ /:::::| |
/:::/\:::\ \ /:::/\:::\ \ /::::::| |
/:::/ \:::\ \ /:::/__\:::\ \ /:::/|::| |
/:::/ \:::\ \ /::::\ \:::\ \ /:::/ |::| |
/:::/ / \:::\ \ /::::::\ \:::\ \ /:::/ |::|___|______
/:::/ / \:::\ ___\ /:::/\:::\ \:::\ \ /:::/ |::::::::\ \
/:::/____/ ___\:::| |/:::/__\:::\ \:::\____\/:::/ |:::::::::\____\
\:::\ \ /\ /:::|____|\:::\ \:::\ \::/ /\::/ / ~~~~~/:::/ /
\:::\ /::\ \::/ / \:::\ \:::\ \/____/ \/____/ /:::/ /
\:::\ \:::\ \/____/ \:::\ \:::\ \ /:::/ /
\:::\ \:::\____\ \:::\ \:::\____\ /:::/ /
\:::\ /:::/ / \:::\ \::/ / /:::/ /
\:::\/:::/ / \:::\ \/____/ /:::/ /
\::::::/ / \:::\ \ /:::/ /
\::::/ / \:::\____\ /:::/ /
\::/____/ \::/ / \::/ /
\/____/ \/____/
######################################################
# #
# gem v3.11 (November 13th 2020) #
# #
# What's New: Add cool ASCII art #
# #
# #
######################################################
import gnupg
import sys
import gnupg._parsers
# monkey patch from https://github.com/isislovecruft/python-gnupg/issues/207
gnupg._parsers.Verify.TRUST_LEVELS["ENCRYPTION_COMPLIANCE_MODE"] = 23
def main(clear_text,
pubkey_file_name='pubkey.asc',
pubkey_file_path='/path/to/pubkey/'):
"""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))