|
@@ -1,40 +1,40 @@
|
|
|
import os
|
|
import os
|
|
|
-import rsa as rsa2
|
|
|
|
|
|
|
+import rsa
|
|
|
|
|
|
|
|
from cryptography.hazmat.backends import default_backend
|
|
from cryptography.hazmat.backends import default_backend
|
|
|
-from cryptography.hazmat.primitives.asymmetric import rsa
|
|
|
|
|
|
|
+#from cryptography.hazmat.primitives.asymmetric import rsa
|
|
|
from cryptography.hazmat.primitives import serialization
|
|
from cryptography.hazmat.primitives import serialization
|
|
|
from cryptography.fernet import Fernet
|
|
from cryptography.fernet import Fernet
|
|
|
|
|
|
|
|
def make_keys(contract_name):
|
|
def make_keys(contract_name):
|
|
|
- #(pubkey,privkey)=rsa.newkeys(2048)
|
|
|
|
|
- private_key = rsa.generate_private_key(
|
|
|
|
|
- public_exponent=65537,
|
|
|
|
|
- key_size=2048,
|
|
|
|
|
- backend=default_backend()
|
|
|
|
|
- )
|
|
|
|
|
- public_key = private_key.public_key()
|
|
|
|
|
-
|
|
|
|
|
- pem = public_key.public_bytes(
|
|
|
|
|
- encoding=serialization.Encoding.PEM,
|
|
|
|
|
- format=serialization.PublicFormat.SubjectPublicKeyInfo
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ (public_key,private_key)=rsa.newkeys(2048)
|
|
|
|
|
+ # private_key = rsa.generate_private_key(
|
|
|
|
|
+ # public_exponent=65537,
|
|
|
|
|
+ # key_size=2048,
|
|
|
|
|
+ # backend=default_backend()
|
|
|
|
|
+ # )
|
|
|
|
|
+ # public_key = private_key.public_key()
|
|
|
|
|
+
|
|
|
|
|
+ # pem = public_key.public_bytes(
|
|
|
|
|
+ # encoding=serialization.Encoding.PEM,
|
|
|
|
|
+ # format=serialization.PublicFormat.SubjectPublicKeyInfo
|
|
|
|
|
+ # )
|
|
|
|
|
|
|
|
path = 'contract_keys\\' + contract_name + '\\'
|
|
path = 'contract_keys\\' + contract_name + '\\'
|
|
|
|
|
|
|
|
os.mkdir(path)
|
|
os.mkdir(path)
|
|
|
|
|
|
|
|
with open(path + 'publickey.key','wb') as f:
|
|
with open(path + 'publickey.key','wb') as f:
|
|
|
- f.write(pem)
|
|
|
|
|
|
|
+ f.write(public_key)
|
|
|
|
|
|
|
|
- pem = private_key.private_bytes(
|
|
|
|
|
- encoding=serialization.Encoding.PEM,
|
|
|
|
|
- format=serialization.PrivateFormat.PKCS8,
|
|
|
|
|
- encryption_algorithm=serialization.NoEncryption()
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ # pem = private_key.private_bytes(
|
|
|
|
|
+ # encoding=serialization.Encoding.PEM,
|
|
|
|
|
+ # format=serialization.PrivateFormat.PKCS8,
|
|
|
|
|
+ # encryption_algorithm=serialization.NoEncryption()
|
|
|
|
|
+ # )
|
|
|
|
|
|
|
|
with open(path + 'privatekey.key','wb') as f:
|
|
with open(path + 'privatekey.key','wb') as f:
|
|
|
- f.write(pem)
|
|
|
|
|
|
|
+ f.write(private_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
symmetric_key = Fernet.generate_key()
|
|
symmetric_key = Fernet.generate_key()
|
|
@@ -53,7 +53,7 @@ def get_keys(contract_name):
|
|
|
# return public_key
|
|
# return public_key
|
|
|
|
|
|
|
|
with open(path, 'rb') as f:
|
|
with open(path, 'rb') as f:
|
|
|
- return rsa2.PublicKey.load_pkcs1(f.read())
|
|
|
|
|
|
|
+ return rsa.PublicKey.load_pkcs1(f.read())
|
|
|
|
|
|
|
|
def get_symmetric_key(contract_name):
|
|
def get_symmetric_key(contract_name):
|
|
|
path = 'contract_keys\\' + contract_name + '\\symmetric.key'
|
|
path = 'contract_keys\\' + contract_name + '\\symmetric.key'
|
|
@@ -64,13 +64,15 @@ def get_symmetric_key(contract_name):
|
|
|
def get_private_key(contract_name):
|
|
def get_private_key(contract_name):
|
|
|
path = 'contract_keys\\' + contract_name + '\\privatekey.key'
|
|
path = 'contract_keys\\' + contract_name + '\\privatekey.key'
|
|
|
|
|
|
|
|
- with open(path, "rb") as key_file:
|
|
|
|
|
- private_key = serialization.load_pem_private_key(
|
|
|
|
|
- key_file.read(),
|
|
|
|
|
- password=None,
|
|
|
|
|
- backend=default_backend()
|
|
|
|
|
- )
|
|
|
|
|
- return private_key
|
|
|
|
|
|
|
+ # with open(path, "rb") as key_file:
|
|
|
|
|
+ # private_key = serialization.load_pem_private_key(
|
|
|
|
|
+ # key_file.read(),
|
|
|
|
|
+ # password=None,
|
|
|
|
|
+ # backend=default_backend()
|
|
|
|
|
+ # )
|
|
|
|
|
+ # return private_key
|
|
|
|
|
+ with open(path, 'rb') as f:
|
|
|
|
|
+ return rsa.PrivateKey.load_pkcs1(f.read())
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_plain_key(contract_name):
|
|
def get_plain_key(contract_name):
|