-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVerify.py
53 lines (42 loc) · 1.6 KB
/
Verify.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
from flask import Blueprint , render_template,request
from pymongo import MongoClient
from check_sign import verifym
from pycoin.ecdsa import generator_secp256k1, sign, verify
import hashlib, secrets
Verify = Blueprint("Verify" , __name__, static_folder="static", template_folder="templates")
URL = "mongodb+srv://vasdoc:vasdoc123@cluster0.1ssyf7f.mongodb.net/test"
cl = MongoClient(URL)
db = cl["filedata"]
db1 = cl["userdata"]
@Verify.route("/Verify")
def verify_file():
fileHash = request.args.get('filehash')
print(type(fileHash))
print(fileHash)
filedata = db.filedata.find({"filehash":fileHash})
print(filedata)
for f in filedata:
signature = (f["signature"])
to = f["to"]
print(signature)
signature = eval(signature)
print(type(signature))
pub = db1.userdata.find({"name" : to})
for f in pub:
pubKey = (f["pubKey"])
pubKey = eval(pubKey)
print(type(pubKey))
print(pubKey)
valid = verifym(fileHash,pubKey,generator_secp256k1,hashlib,signature,verify)
# hashBytes = hashlib.sha3_256(fileHash.encode("utf8")).digest()
# hashBytes = int.from_bytes(hashBytes, byteorder="big")
# validated = verify(generator_secp256k1, pubKey, fileHash, signature)
# print(validated)
print(valid)
if valid:
message = "Valid Document Signed by\t"+to
return render_template("Verify.html",message = message)
else:
message = "Invalid Document"
return render_template("Verify.html",message = message)
return render_template("Verify.html")