edq.cli.crypto.encrypt-secret
Encrypt a cleartext string as an edq.util.crypto.Secret.
The standard configuration encryption key will be used.
1# pylint: disable=invalid-name 2 3""" 4Encrypt a cleartext string as an edq.util.crypto.Secret. 5 6The standard configuration encryption key will be used. 7""" 8 9import argparse 10import sys 11 12import edq.config.constants 13import edq.core.argparser 14import edq.util.crypto 15 16def run_cli(args: argparse.Namespace) -> int: 17 """ Run the CLI. """ 18 19 secret = edq.util.crypto.Secret(args.cleartext, iv_b64 = args.iv, salt_b64 = args.salt) 20 ciphertext = secret.encrypt(args._config_info.application_config.encryption_key) 21 22 print(ciphertext) 23 24 return 0 25 26def main() -> int: 27 """ Get a parser, parse the args, and call run. """ 28 return run_cli(_get_parser().parse_args()) 29 30def _get_parser() -> argparse.ArgumentParser: 31 """ Get the parser. """ 32 33 parser = edq.core.argparser.get_default_parser(__doc__.strip()) 34 35 parser.add_argument('cleartext', metavar = 'TEXT', 36 action = 'store', type = str, 37 help = 'The text to encrypt.') 38 39 parser.add_argument('--encryption-method', dest = 'encryption_method', 40 action = 'store', type = str, default = edq.util.crypto.EncryptionMethod.AES256v1.value, 41 choices = [choice.value for choice in edq.util.crypto.EncryptionMethod], 42 help = 'The encryption method to use (default: %(default)s).') 43 44 parser.add_argument('--salt', dest = 'salt', 45 action = 'store', type = str, default = None, 46 help = ('An optional salt to provide (as a base64 encoded string).' 47 + ' Providing a salt is not recommended.' 48 + ' If no salt is provided, one will be generated randomly.') 49 ) 50 51 parser.add_argument('--iv', dest = 'iv', 52 action = 'store', type = str, default = None, 53 help = ('An optional initialization vector (IV) to provide (as a base64 encoded string).' 54 + ' Providing an IV is not recommended.' 55 + ' If no IV is provided, one will be generated randomly.') 56 ) 57 58 return parser 59 60if (__name__ == '__main__'): 61 sys.exit(main())
def
run_cli(args: argparse.Namespace) -> int:
17def run_cli(args: argparse.Namespace) -> int: 18 """ Run the CLI. """ 19 20 secret = edq.util.crypto.Secret(args.cleartext, iv_b64 = args.iv, salt_b64 = args.salt) 21 ciphertext = secret.encrypt(args._config_info.application_config.encryption_key) 22 23 print(ciphertext) 24 25 return 0
Run the CLI.
def
main() -> int:
27def main() -> int: 28 """ Get a parser, parse the args, and call run. """ 29 return run_cli(_get_parser().parse_args())
Get a parser, parse the args, and call run.