paulbsd-salt/scripts/encrypt_password.py

33 lines
731 B
Python
Raw Normal View History

#!/usr/bin/python3
import argparse
import gnupg
2021-01-17 17:45:09 +01:00
2020-09-30 00:24:02 +02:00
KEYID = "salt"
GPGHOME = "/etc/salt/gpgkeys"
2021-01-17 17:45:09 +01:00
def parse_args():
parser = argparse.ArgumentParser(description='Encrypt password')
2022-10-23 16:40:45 +02:00
parser.add_argument('password',
type=str,
nargs=1,
help='password to encrypt')
args = parser.parse_args()
return args
2021-01-17 17:45:09 +01:00
def encrypt(password=""):
2022-10-23 16:40:45 +02:00
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(encrypt(Password))