Print Page | Close Window

Detached signature with sha256 digest

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3428
Printed Date: 29 Apr 24 at 5:02AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Detached signature with sha256 digest
Posted By: pinozzy
Subject: Detached signature with sha256 digest
Date Posted: 02 Jan 17 at 6:00PM
Hello, i'm trying to add a visual sha-256 detached signature to my pdf.


I did it successfully with this example: http://www.debenu.com/kb/advanced-options-signing-pdf-files/

I edited this method

private byte[] SignData(byte[] inputData, X509Certificate2 cert)
        {
            // Create an SHA-1 hash of the file data
            SHA1 sha = new SHA1CryptoServiceProvider();
            byte[] sha1Result = sha.ComputeHash(inputData);

            // Sign the hash using the certificate
            // This could be changed to use a hardware device (eg. smartcard)
            ContentInfo content = new ContentInfo(sha1Result);
            SignedCms signedCms = new SignedCms(content);
            CmsSigner cmsSigner = new CmsSigner(cert);
            signedCms.ComputeSignature(cmsSigner);
            return signedCms.Encode();
        }

this way:

private byte[] SignData(byte[] inputData, X509Certificate2 cert)
    {
      // Create an SHA-1 hash of the file data
      var sha = new SHA256CryptoServiceProvider();
      byte[] sha1Result = sha.ComputeHash(inputData);

      // Sign the hash using the certificate
      // This could be changed to use a hardware device (eg. smartcard)

      var oid = new Oid("2.16.840.1.101.3.4.2.1");
      var content = new ContentInfo(oid, sha1Result);
      var signedCms = new SignedCms(content, true);

      var cmsSigner = new CmsSigner(cert);
      cmsSigner.DigestAlgorithm = oid;


      signedCms.ComputeSignature(cmsSigner);
      return signedCms.Encode();
    }

And i just added this: DPL.SetSignProcessSubFilter(signProcessID, 2);

For the detached signature.

I got an error from adobe reader, the document signature is visible but with red X and the message of damaged signature.

Does anyone have a working example of Detached sha-256 signature?

Many thanks all.






Replies:
Posted By: Ingo
Date Posted: 02 Jan 17 at 11:14PM
Hi,

perhaps here you can learn more about sha256:
https://msdn.microsoft.com/de-de/library/system.security.cryptography.sha256cryptoserviceprovider(v=vs.110).aspx



-------------
Cheers,
Ingo




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk