Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Detached signature with sha256 digest |
Post Reply |
Author | |
pinozzy
Beginner Joined: 22 Mar 16 Status: Offline Points: 10 |
Post Options
Thanks(0)
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. |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
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 |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store