forked from stefan-contiu/trusted-sharing
-
Notifications
You must be signed in to change notification settings - Fork 2
/
crypto.py
74 lines (54 loc) · 1.69 KB
/
crypto.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
from cryptography.hazmat.backends.openssl import backend as openssl
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.serialization import *
from collections import OrderedDict
class UserKeyLoader:
path = 'rsa_keys/'
@staticmethod
def pri_key(user):
with open(UserKeyLoader.path + user + '.pri', 'rb') as fkey:
key_data = fkey.read()
pri_key = load_pem_private_key(key_data, password=None, backend=openssl)
return pri_key
@staticmethod
def pub_key(user):
with open(UserKeyLoader.path + user + '.pub', 'rb') as fkey:
key_data = fkey.read()
pub_key = load_pem_public_key(key_data, backend=openssl)
return pub_key
class PKI:
path = 'rsa_keys/'
keys = OrderedDict()
@staticmethod
def load():
for file in os.listdir(PKI.path):
if file.endswith(".pub"):
user = os.path.splitext(file)[0]
PKI.keys[user] = UserKeyLoader.pub_key(user)
return len(PKI.keys.keys())
@staticmethod
def get(user):
if not len(PKI.keys):
PKI.load()
return PubKeysLookup.k[user]
@staticmethod
def get_index(user):
if not len(PKI.keys):
PKI.load()
return list(PKI.keys.keys()).index(user) + 1
class AONT:
@staticmethod
def transform(self, s):
pass
# generate a random key
# alter the whole s by rand key
#
#E1(K, XXXXXXXXXXXXXXXXXXXXXXX)
#E2(K, Y)
#H(XXXXXXX) ^ H(Y) ^ K
#BE(K), FFFFFFFFFFFFFFFFFFF
pass
@staticmethod
def combine(self, package, stub):
pass