-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyGen.py
More file actions
29 lines (25 loc) · 734 Bytes
/
Copy pathKeyGen.py
File metadata and controls
29 lines (25 loc) · 734 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
import math
import secrets
import string
import base64
import pickle
from Crypto.PublicKey import RSA
from Crypto.Cipher import AES, PKCS1_OAEP
from bz2 import BZ2File
from random import randint
class KeyGen:
def generateRsaKey(self):
rsa = RSA.generate(2048)
self.privateKey = rsa
self.publicKey = rsa.publickey()
self.storeKeys()
def saveKey(self, fileName, key):
file = BZ2File(fileName, 'w')
pickle.dump(key.exportKey(), file)
file.close()
def storeKeys(self):
randomInt = randint(0, 100)
fileName = 'Private Key'
self.saveKey(fileName, self.privateKey)
fileName = 'Public Key'
self.saveKey(fileName, self.publicKey)