Get hash of a digital signature file

we need to send digital signature hash to signing authority to get the hash signed.

we are using aspose.pdf to sign the documents. need to know how to get the hash of signed file and how to put signed hash to digital signature.

Code

string _dataDir = @“C:\Temp”;
Aspose.Pdf.Facades.PdfFileSignature pdfSign = new Aspose.Pdf.Facades.PdfFileSignature();
pdfSign.BindPdf(_dataDir + “test.pdf”);

            // Create a rectangle for signature location
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(10, 10, 300, 50);
            pdfSign.SignatureAppearance = _dataDir + "gb.png";
            // Set signature appearance


            // Create any of the three signature types
            PKCS1 signature = new PKCS1(_dataDir + "gb.pfx", "gaurav"); // PKCS#1

            
            pdfSign.Sign(1, "Verification", "Gaurav.Bhatnagar@test.com", "test", true, rect, signature);

        
            // Save output PDF file
            pdfSign.Save(_dataDir + "DigitallySign.pdf");

@gauravb

We need to further investigate this requirement and for the sake, an investigation ticket as PDFNET-53393 has been logged in our issue tracking system. We will further look into its details and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

@gauravb

You can use new property “CustomSignHash” for PKCS7. He can use data from “signableHash”.

var inputPfx = dataDir + ("your file.pfx");
var inputPfxPassword = "your password";
SignHash customSignHash = delegate (byte[] signableHash)
{//Get Hash of document here
    X509Certificate2 signerCert = new X509Certificate2(inputPfx, inputPfxPassword, X509KeyStorageFlags.Exportable);
    RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
    var xmlString = signerCert.PrivateKey.ToXmlString(true);
    rsaCSP.FromXmlString(xmlString);
    byte[] signedData = rsaCSP.SignData(signableHash, CryptoConfig.MapNameToOID("SHA1"));
    return signedData;//return signed hash here
};
var pdfSign = new Aspose.Pdf.Facades.PdfFileSignature();
pdfSign.BindPdf(dataDir + "sample.pdf");
var rect = new System.Drawing.Rectangle(10, 10, 300, 50);
var signature = new PKCS7(inputPfx, inputPfxPassword);
signature.CustomSignHash = customSignHash;
pdfSign.Sign(1, "Verification", "Gaurav.Bhatnagar@test.com", "test", true, rect, signature);
pdfSign.Save(dataDir + "DigitallySign.pdf");//customSignHash will called here