Last active
January 21, 2022 16:24
-
-
Save bjoerntx/f3b1416e781bb221700be6c07edf27b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
[Route("Document/ValidateDocument")] | |
public bool ValidateDocument(string document, string blockHash) | |
{ | |
if (document == null || blockHash == null) | |
return false; | |
// calculate the MD5 of the uploaded document | |
string sChecksum = Checksum.CalculateMD5(Convert.FromBase64String(document)); | |
// load the associated blockchain | |
Blockchain bcDocument = new Blockchain(sBlockchainPath); | |
Block blockDocument = bcDocument.GetBlock(blockHash); | |
if (blockDocument == null) | |
return false; | |
if (bcDocument.IsValid(blockDocument.BlockHash)) { | |
// get the SignedDocument object from the block | |
SignedDocument signedDocument = | |
JsonConvert.DeserializeObject<SignedDocument>(blockDocument.Data); | |
// compare the checksum in the stored block | |
// with the checksum of the uploaded document | |
return (signedDocument.Hash == sChecksum ? true : false); | |
} | |
else return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment