Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active January 21, 2022 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/f3b1416e781bb221700be6c07edf27b5 to your computer and use it in GitHub Desktop.
Save bjoerntx/f3b1416e781bb221700be6c07edf27b5 to your computer and use it in GitHub Desktop.
[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