-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
37 lines (25 loc) · 764 Bytes
/
main.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
35
36
37
import os
import base64
import uuid
import json
def generate_random_bytes(size):
return os.urandom(size)
def generate_uuid():
return uuid.uuid4()
def get_base64(bytes):
return base64.b64encode(bytes).decode('utf-8')
if __name__ == "__main__":
key_id = generate_uuid()
key = generate_random_bytes(16)
iv = generate_random_bytes(16)
data = {}
data['key_id_guid'] = str(key_id)
data['key_id_hex'] = key_id.hex
data['key_id_b64'] = get_base64(key_id.bytes)
data['key_hex'] = key.hex()
data['key_b64'] = get_base64(key)
data['iv_hex'] = iv.hex()
data['iv_b64'] = get_base64(iv)
with open('key.txt', 'w') as outfile:
json.dump(data, outfile, indent=1)
print(json.dumps(data, indent=1))