-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.py
More file actions
28 lines (21 loc) · 916 Bytes
/
encrypt.py
File metadata and controls
28 lines (21 loc) · 916 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
import argparse
import gnupg
def encode_data(data, public_key_file):
gpg = gnupg.GPG()
with open(public_key_file, "r") as f:
key_data = f.read()
import_result = gpg.import_keys(key_data)
public_key = import_result.fingerprints[0]
encrypted_data = gpg.encrypt(data, recipients=None, armor=True, always_trust=True, key_data=public_key)
return encrypted_data
def main():
parser = argparse.ArgumentParser(description="PGP data encoder")
parser.add_argument("-d", "--data", type=str, required=True, help="Data to encode")
parser.add_argument("-b", "--public-key-file", type=str, required=True, help="Public key file")
args = parser.parse_args()
encoded_data = encode_data(args.data, args.public_key_file)
print("Data encoded successfully!")
print("Encoded data:")
print(encoded_data.data.decode('utf-8'))
if __name__ == "__main__":
main()