forked from tecnico-sec/Python-Crypto-Details
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAESKeyGenerator.py
More file actions
40 lines (32 loc) · 862 Bytes
/
Copy pathAESKeyGenerator.py
File metadata and controls
40 lines (32 loc) · 862 Bytes
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
38
39
40
import base64
import os
from sys import argv
class AESKeyGenerator:
def write(keypath):
print("Generating AES key ...")
key = os.urandom(16)
print( "Finish generating AES key" )
f = open(keypath, "wb")
f.write(key)
f.close
def read(keypath):
print("Reading key from file " + keypath + " ...")
f = open(keypath, "rb")
key = f.read()
f.close
return key
def main(argv):
if (len(argv) != 3):
print("Usage: AESKeyGenerator [r|w] <key-file>")
return
mode = argv[1]
keyPath = argv[2]
if (mode.lower() == "w"):
print("Generate and save keys")
AESKeyGenerator.write(keyPath)
else:
print("Load keys")
AESKeyGenerator.read(keyPath)
print("Done.")
if __name__ == '__main__':
main(argv)