-
Notifications
You must be signed in to change notification settings - Fork 4
/
github-secrets.py
executable file
·26 lines (21 loc) · 1002 Bytes
/
github-secrets.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
#!/usr/bin/env python
import sys, argparse, json
from base64 import b64encode
from nacl import encoding, public
def encrypt( encrypt_key: str, secret_value: str ) -> str:
private_key = public.PrivateKey.generate()
public_key = public.PublicKey( encrypt_key.encode( "utf-8" ), encoding.Base64Encoder() )
sealed_box = public.SealedBox( public_key )
encrypted = sealed_box.encrypt( secret_value.encode( "utf-8" ) )
### print(encrypted)
return b64encode( encrypted ).decode( "utf-8" )
def main():
## print ( 'Total Arguments?:', format( len( sys.argv ) ) )
## print ( ' Argument List:', str( sys.argv ) )
parser = argparse.ArgumentParser()
parser.add_argument( '--public-key', dest='public_key', type=str, help='Encryption Public-Key' )
parser.add_argument( '--content', dest='content', type=str, help='Source Content' )
options = parser.parse_args()
print( encrypt( options.public_key, options.content ) )
if __name__ == '__main__':
main()