2024-11-12 10:26:56 +00:00
|
|
|
#!/bin/python3
|
|
|
|
import sys
|
|
|
|
import logging
|
2024-11-17 19:37:41 +00:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
from cryptLib import keyPair
|
2024-11-12 10:26:56 +00:00
|
|
|
|
|
|
|
logging.basicConfig(format='%(levelname)s\t- %(message)s')
|
|
|
|
logger = logging.getLogger()
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
|
|
|
# Generate a key pair for a subject
|
|
|
|
# password - file for keys
|
|
|
|
def generateKeyPair(args):
|
|
|
|
|
2024-11-17 19:37:41 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
|
|
|
parser.add_argument('password', nargs='?', default=None)
|
|
|
|
parser.add_argument('file', nargs='?', default=None)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if len(args) != 2:
|
2024-11-12 10:26:56 +00:00
|
|
|
logger.error("Need password and file to store keys")
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
|
|
|
|
#Generate the key pair
|
2024-11-17 19:37:41 +00:00
|
|
|
keys = keyPair.generate_key_pair(args.password)
|
2024-11-12 10:26:56 +00:00
|
|
|
|
|
|
|
#Get the 2 different keys
|
|
|
|
pubKey = ''
|
|
|
|
privateKey = ''
|
|
|
|
|
2024-11-17 19:37:41 +00:00
|
|
|
with open(args.file, "wb") as f:
|
2024-11-12 10:26:56 +00:00
|
|
|
f.write(pubKey.encode() + b"\n\n" + privateKey.encode())
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
generateKeyPair(sys.argv)
|
|
|
|
|