-
Notifications
You must be signed in to change notification settings - Fork 12
/
generate_keys.py
37 lines (31 loc) · 1.28 KB
/
generate_keys.py
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
"""
Script to generate a private and public RSA key.
The public key should be deployed on the Cryptopuck and will be used to encrypt
the AES secret which will have encrypted the files. Will work on both Windows
and Linux.
"""
import os
import argparse
from Crypto.PublicKey import RSA
def main():
parser_description = "Generate a public and private RSA key pair"
parser = argparse.ArgumentParser(description=parser_description)
parser.add_argument("--destination",
help="Path to where the key pair will be exported",
default="./")
args = parser.parse_args()
# Generate private key
private_key = RSA.generate(2048)
# Derive the public key
public_key = private_key.publickey()
# Save the keys into files
public_key_file = args.destination + "key.public"
private_key_file = args.destination + "key.private"
with open(public_key_file, "wb") as public_file:
public_file.write(public_key.exportKey())
print("Generated public key at: " + os.path.abspath(public_key_file))
with open(private_key_file, "wb") as private_file:
private_file.write(private_key.exportKey())
print("Generated private key at: " + os.path.abspath(private_key_file))
if __name__ == "__main__":
main()