FileStream documentStream = new FileStream("PDF_Succinctly.pdf ", FileMode.Open, FileAccess.Read);
//Load the existing PDF document
PdfLoadedDocument document = new PdfLoadedDocument(documentStream);
//Creates a digital signature
PdfSignature signature = new PdfSignature(document, document.Pages[0], null, "DigitalSignature");
signature.ComputeHash += Signature_ComputeHash;
MemoryStream ms = new MemoryStream();
document.Save(ms);
document.Close(true);
private static void Signature_ComputeHash1(object sender, PdfSignatureEventArgs ars)
{
//Get the document bytes and calculate the hash of the bytes.
byte[] hash = System.Security.Cryptography.SHA512.Create().ComputeHash(ars.Data);
} |
How about if the pdf password protected? |
Yes, we can use the same code for the password-protected PDF documents too. |