#!/bin/python3 import os import sys import logging import argparse from lib import decryption_functs logging.basicConfig(format='%(levelname)s\t- %(message)s') logger = logging.getLogger() logger.setLevel(logging.INFO) #send to stdout contents of decrypted file # encrypted file - encryption metadata def decryptFile(args): parser = argparse.ArgumentParser() parser.add_argument('encrypted', nargs='?', default=None) parser.add_argument('metadata', nargs='?', default=None) args = parser.parse_args() if len(args) != 2: logger.error("Need encrypted file and it's metadata.") sys.exit(-1) # If first argument is not a file or not found if (not os.path.isfile(args.encrypted)): logger.error("File '" + args.encrypted + "' not found.") sys.exit(-1) if (not os.path.isfile(args.metadata)): logger.error("File '" + args.metadata + "' not found.") sys.exit(-1) #Get private key to decrypt privateKey = decryption_functs.load_private_key(args.metadata) #Decrypt file with open(args.encrypted, 'rb') as f: content = f.read() content = decryption_functs.decrypt_file(privateKey, content) # Send decrypted content to stdout sys.stdout.write(content) if __name__ == '__main__': decryptFile(sys.argv[1:])