2020-08-29 11:40:30 +02:00
|
|
|
#!/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"
|
2020-08-29 11:40:30 +02:00
|
|
|
|
2021-01-17 17:45:09 +01:00
|
|
|
|
2020-08-29 11:40:30 +02: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,
|
2020-08-29 11:40:30 +02:00
|
|
|
help='password to encrypt')
|
|
|
|
args = parser.parse_args()
|
|
|
|
return args
|
|
|
|
|
2021-01-17 17:45:09 +01:00
|
|
|
|
2020-08-29 11:40:30 +02: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)
|
2020-08-29 11:40:30 +02:00
|
|
|
return encrypted_password
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
Args = parse_args()
|
|
|
|
Password = Args.password[0]
|
|
|
|
print(encrypt(Password))
|