fixes transactions
This commit is contained in:
@@ -3,6 +3,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives.asymmetric import padding
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
|
||||
def generateKeys():
|
||||
private_key = rsa.generate_private_key(public_exponent=65537,key_size=2048)
|
||||
@@ -43,29 +44,31 @@ def bytesToKeys(private_ser, public_ser):
|
||||
|
||||
def publicBytesToKey(public_ser):
|
||||
public_key = serialization.load_pem_public_key(
|
||||
public_ser
|
||||
public_ser,
|
||||
backend=default_backend()
|
||||
)
|
||||
return public_key
|
||||
|
||||
def privateBytesToKey(private_ser):
|
||||
private_key = serialization.load_pem_private_key(
|
||||
private_ser,
|
||||
password=None
|
||||
password=None,
|
||||
backend=default_backend()
|
||||
)
|
||||
return private_key
|
||||
|
||||
def sign(message, private_key):
|
||||
message = bytes(str(message), 'utf-8')
|
||||
key = privateBytesToKey(private_key)
|
||||
signature = key.sign(
|
||||
signature = private_key.sign(
|
||||
message,
|
||||
padding.PSS(mgf=padding.MGF1(hashes.SHA256()), salt_length=padding.PSS.MAX_LENGTH),
|
||||
hashes.SHA256()
|
||||
)
|
||||
return signature
|
||||
|
||||
def verify(message, signature, public_key):
|
||||
def verify(message, signature, public_ser):
|
||||
message = bytes(str(message), 'utf-8')
|
||||
public_key = publicBytesToKey(public_ser)
|
||||
try:
|
||||
public_key.verify(
|
||||
signature,
|
||||
|
Reference in New Issue
Block a user