-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIVsKeys.py
39 lines (35 loc) · 831 Bytes
/
IVsKeys.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
38
39
import os
from cryptography.fernet import Fernet
def generateIV():
iv1 = os.urandom(16)
iv2 = os.urandom(8)
f=open(os.path.join(os.getcwd()+"/Keys_IV",'IV.txt'),'wb')
f.write(iv1)
f.write(b"::::")
f.write(iv2)
f.close()
return iv1,iv2
def generateKey():
k1 = os.urandom(16)
k2 = Fernet.generate_key()
f=open(os.path.join(os.getcwd()+"/Keys_IV",'k1.txt'),'wb')
f.write(k1)
f.close()
f=open(os.path.join(os.getcwd()+"/Keys_IV",'k2.txt'),'wb')
f.write(k2)
f.close()
return k1,k2
def FetchIV():
f=open(os.path.join(os.getcwd()+"/Keys_IV",'IV.txt'),'rb')
cont=f.read()
f.close()
iv=cont.split(b"::::")
return iv
def FetchKey():
f=open(os.path.join(os.getcwd()+"/Keys_IV",'k1.txt'),'rb')
k1=f.read()
f.close()
f=open(os.path.join(os.getcwd()+"/Keys_IV",'k2.txt'),'rb')
k2=f.read()
f.close()
return k1,k2