diff --git a/scripts/encrypt_password b/scripts/encrypt_password deleted file mode 100755 index 0a8cb8b..0000000 --- a/scripts/encrypt_password +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -key_id=salt - -if [[ $1 != "" ]] -then - echo -n $1 | gpg --armor --batch --homedir="/etc/salt/gpgkeys" --trust-model always --encrypt -r "${key_id}" -else - echo "Please specify a password" -fi diff --git a/scripts/encrypt_password.py b/scripts/encrypt_password.py new file mode 100755 index 0000000..ae8ba28 --- /dev/null +++ b/scripts/encrypt_password.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 + +import argparse +import gnupg + +KEYID="salt" +GPGHOME="/etc/salt/gpgkeys" + +def parse_args(): + parser = argparse.ArgumentParser(description='Encrypt password') + parser.add_argument('password', type=str, nargs=1, + help='password to encrypt') + args = parser.parse_args() + return args + +def encrypt(password=""): + gpg = gnupg.GPG(gnupghome=GPGHOME, secret_keyring=KEYID) + encrypted_password = gpg.encrypt(password, KEYID) + return encrypted_password + + +if __name__ == "__main__": + Args = parse_args() + Password = Args.password[0] + print(f"Encrypting password {Password}") + print(encrypt(Password))