-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryptPasswords.py
More file actions
34 lines (28 loc) · 835 Bytes
/
Copy pathEncryptPasswords.py
File metadata and controls
34 lines (28 loc) · 835 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
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
from Crypto.Hash import SHA256
def generate_sk():
key = RSA.generate(16384)
with open("secret_key.pem", "wb") as f_out:
f_out.write(key.export_key(format='PEM'))
return key
def import_key(file_name):
with open(file_name, 'rb') as f_in:
key = RSA.import_key(f_in.read())
return key
def generate_pk(sk):
pk = sk.publickey()
with open("public_key.pem", "wb") as f_out:
f_out.write(pk.export_key(format='PEM'))
return pk
def encrypt(pk_receiver, message):
cipher = PKCS1_OAEP.new(pk_receiver)
c = cipher.encrypt(message)
return c
def decrypt(sk, c):
cipher = PKCS1_OAEP.new(sk)
m = cipher.decrypt(c)
return m
def footprint(pk):
hasher = SHA256.new(pk)
return hasher.digest()