forked from benoitf/github-secrets-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.py
executable file
·34 lines (30 loc) · 965 Bytes
/
generate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from base64 import b64encode
from nacl import encoding, public
import json
import sys
key = sys.argv[1]
# first secret could be a login
firstSecret = sys.argv[2]
# second secret could be a password, ot omitted if only using a key/token
if len(sys.argv) > 3:
secondSecret = sys.argv[3]
else:
secondSecret = ""
def encrypt(public_key: str, secret_value: str) -> str:
"""Encrypt a Unicode string using the public key."""
public_key = public.PublicKey(public_key.encode("utf-8"), encoding.Base64Encoder())
sealed_box = public.SealedBox(public_key)
encrypted = sealed_box.encrypt(secret_value.encode("utf-8"))
return b64encode(encrypted).decode("utf-8")
encodedfirstSecret = encrypt(key, firstSecret)
if secondSecret != "":
result = {
"firstSecret": encodedfirstSecret,
"secondSecret": encrypt(key, secondSecret)
}
else:
result = {
"firstSecret": encodedfirstSecret
}
jsonStr = json.dumps(result, indent=2)
print(jsonStr)