c# - Return SHA256 hash of PDF page -


I am writing a C # WPF application, where I have a 'header' as the first page of the batch of PDF documents. Enter the page. The header page is taken from the first page of the first pdf in the batch.

The user will implicate this process, but I want to ensure that at the later date the user can not run the process again, the other headers will be included.

Then I want to get the SHA256 hash of my plan header page and compare it with the hash of the first page of the second PDFs, if they match, then the first page is like the header page, Do not include the article.

I have suppressed the code below to get the hash of the first page in PDF, but the hash is different each time it is run.

Why is it different every time?

Thanks

  using System.IO; Using System.Text; Using System.Security.Cryptography; Using PdfSharp.Pdf; Using PdfSharp.Pdf.IO; Namespace Sinkada {Public Class PDF Doc {Private PDF Document PDFFed; Public PDFDoc (string path) {pdfDoc = PdfReader.Open (Path, PdfDocumentOpenMode.Import); } Public string GetPageOneHash () {byte [] hash; PDF page page = PDF file. Page [0]; (Using memorystream stream = new memorystream ()) {PDF document document = new PDF document (); Doc.AddPage (page); Doc.Save (Section, False); SHA256 sha256 = SHA256.Create (); Hash = sha256 Compute hash (stream); } Stringbiller sb = New stringbilder (); For (int i = 0; i & lt; hash.Length; i ++) {sb.Append (hash [i]. Ostring ("x2"); } Return sb.ToString (); }}}}    

I get the code given below to get a hash The first page in PDF is suppressed, but the hash is run every time.

Why is it different every time?

You have the hash of page the hash of a new PDF document on which you add pages to the question unfortunately for your efforts , PDF documents contain information like date of creation, date of last revision and a unique ID. As these information differs from time to time, when you calculate a hash, you will never receive the same hash (unless you have any conflicts).

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -