encrypt_password script converted to python3

This commit is contained in:
Paul 2020-08-29 11:40:30 +02:00
parent 1f3e165b79
commit 3ade049133
2 changed files with 26 additions and 10 deletions

View File

@ -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

26
scripts/encrypt_password.py Executable file
View File

@ -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))