The problem is the code is working but it does not verify. The sample below was the first iteration of the implementation of the code. below. That code operates accurately, but once I save the signature in Sqlite (base64 encoded) server and retrieve it back for comparison, it does not work. The link is the full project where you can see the issue. The project run on flask and all the requirements can be found in the requirements.txt
file.
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.serialization import load_pem_private_key, load_pem_public_key, Encoding, PublicFormat
from cryptography.hazmat.primitives.asymmetric import utils
with open("CA_test\\private_key.pem", 'rb') as f:
private_key = load_pem_private_key(f.read(), None)
with open("CA_test\\public_key.pem", 'rb') as f:
public_key = load_pem_public_key(f.read(), None)
# Create SHA-256 hash of message
message = b'14789'
message_hash = hashes.Hash(hashes.SHA256())
message_hash.update(message)
message_digest = message_hash.finalize()
message1 = b'14789'
message_hash1 = hashes.Hash(hashes.SHA256())
message_hash1.update(message1)
message_digest1 = message_hash1.finalize()
# Generate proof
signature = private_key.sign(message_digest, ec.ECDSA(utils.Prehashed(hashes.SHA256())))
print(signature)
try:
public_key.verify(signature, message_digest1, ec.ECDSA(utils.Prehashed(hashes.SHA256())))
print('Proof verified')
except:
print('Proof not verified')
That pyodide with flask can verify the data, by using the signature sent by the database and authenticate the user.