Free Support Forum - aspose.com

Aspose.Pdf v6.0 vs Aspose.Pdf.Kit v5.5 signing issues

Hi,


We have a site licence for Aspose.Pdf, but are experiencing issues when signing documents compared with the earlier Aspose.Pdf.Kit.

When signing document using the Aspose.Pdf.Kit we experience no issues, however when signing using the newer Aspose.Pdf.Facades Sign method an exception is thrown.

I’ve attached a complete code sample of the issue, showing the older components working and the newer components throwing an exception.

The error generated is;

"System.ArgumentOutOfRangeException:
Index was out of range. Must be non-negative and less than the size of the
collection.\r\nParameter name: index\r\n at
System.Collections.ArrayList.get_Item(Int32 index)\r\n at •..P’2(Byte[]
contents, _pfx)\r\n at •..Byte[] contents, Stream pfxFile, String
password)\r\n at —.
._String sigName,  signature, _params, Stream pfx, String
pass)\r\n at Aspose.Pdf.InteractiveFeatures.Forms.Signature.P’2(String
sigName, Stream pfx, String pass)\r\n at
Aspose.Pdf.InteractiveFeatures.Forms.SignatureField.Sign(Signature signature,
Stream pfx, String pass)\r\n at
Aspose.Pdf.InteractiveFeatures.Forms.SignatureField.Sign(Signature
signature)\r\n at Aspose.Pdf.Facades.PdfFileSignature.Save(Stream
outputStream)

Advice would be most appreciated as this is project critical

Many thanks

Matthew

<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p>

Hi Matthew,

Thank you for sharing the sample project.

We have found your mentioned issue after an initial test. You issue has been registered in our issue tracking system with issue id:PDFNEWNET-30480. You will be notified via this forum thread regarding any update against your issue.

Sorry for the inconvenience caused,

Hi Matthew,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

We have further tested your issue with latest version of Aspose.Pdf for .NET V6.2.0 and it works fine (no exception on save method). Please download and try the latest version from the following location and let us know if it works fine for you.

http://www.aspose.com/community/files/51/.net-components/aspose.pdf-for-.net/entry327880.aspx

Thank You & Best Regards,

Hi,


I’ve downloaded version 6.2.0 and I still get exactly the same issue as documented in my initial post using the same test project (with the references updated to use v6.2).


Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


at System.Collections.ArrayList.get_Item(Int32 index)
at ‚.™.(Byte[] , )
at ‚.™.(Byte[] , Stream , String )
at „..(String , ˜ , ™ , Stream , String )
at Aspose.Pdf.InteractiveFeatures.Forms.Signature.(String , Stream , String )
at Aspose.Pdf.InteractiveFeatures.Forms.SignatureField.Sign(Signature signature, Stream pfx, String pass)
at Aspose.Pdf.InteractiveFeatures.Forms.SignatureField.Sign(Signature signature)
at Aspose.Pdf.Facades.PdfFileSignature.Save(Stream outputStream)
at AsposeTestRig.Core.ApplyPDFSignatureNew(Byte[] pdfDocument) in C:\Documents and Settings\p63487\My Documents\Visual Studio 2005\Projects\AsposeTestRig\AsposeTestRig\Core.cs:line 53
at AsposeTestRig.TestRigWindow.btnPDFNew_Click(Object sender, EventArgs e) in C:\Documents and Settings\p63487\My Documents\Visual Studio 2005\Projects\AsposeTestRig\AsposeTestRig\TestRigWindow.cs:line 55

Hi Matthew,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please share your system environment details i.e. OS Version, Visual Studio and .NET Framework you are using. Also, please create a separate application using only Aspose.Pdf for .NET (not using Aspose.Pdf.Kit) and see if it works fine?

Thank You & Best Regards,

Hi,


I’ve tried this on multiple environments.

Windows XP using VS 2005 with .Net 2.0 (normal environment for us)

Windows 7 using VS 2010 with .Net 2.0 and .Net 4.0 runtime.

I am using a project only referencing Aspose.Pdf and still the issue is apparent.

Hi Matthew,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Well, I have tested the issue with same environment as your system (Windows XP with Visual Studio 2005 and .NET Framework 3.5) and I am unable to reproduce the issue with V6.2. Please try the following simple code and see if this works fine or you still get the exception your reported previously:

string inFile = @"E:\AP Data\Source_Files\sample.pdf";

string outFile = @"E:\AP Data\Source_Files\test-signed.pdf";

PKCS1 sig = new PKCS1(@"E:\AP Data\Source_Files\MyPFX.pfx", "toto");

sig.Reason = "Some reason";

sig.ContactInfo = "Smith";

sig.Location = "New York";

PdfFileSignature pdfSign = new PdfFileSignature(inFile, outFile);

System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);

pdfSign.Sign(1, true, rect, sig);

pdfSign.Save();

Thank You & Best Regards,

This will work. However if you look at what I am going in the sample project, I am reading the pfx certificate out of the local machine keystore not a file.


If I get the certificate from a file or indeed the CurrentUser location in the keystore all works OK. If I read the certificate from the LocalMachine area of the keystore, I get an error.

In the initial sample project I sent, you can see the Aspose.Pdf.Key example I coded I can successfully sign a PDF using a certificate from the LocalMachine area of the keystore, in Aspose.Pdf I can’t.

This is the issue.

Hi Matthew,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the further details and clarifying the issue.

I am able to reproduce the issue when using StoreLocation.LocalMachine. I have re-opened the issue and informed the development team to further look into the issue. You will be notified via this forum thread regarding any update against your issue.

Sorry for the inconvenience caused,

Hi,


This issue is seriously hampering us deploying our software.

Is there any way we can use a licence for the older Aspose.Pdf.Kit components until this issue is resolved in Aspose.Pdf? We have a licence for Aspose.Pdf - order id 110715094928.

Many thanks

matandrews:
This will work. However if you look at what I am going in the sample project, I am reading the pfx certificate out of the local machine keystore not a file.


I am encountering this issue as well. I am accessing the "StoreName.My" keystore.

Hi Matthew,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Well, at the moment, our development team is not able to reproduce the issue at their end and we are trying to figure out the issue (as I am able to reproduce the issue at my machine). However, our development team and I used the following code to register the certificate to the store and using that for signing and it works fine. Could you please try using the following code at your end and see if it works fine for you too and fulfill your requirement:

///

/// Read the keystore and return a PKCS1 object

///

/// A PKCS1 object - signing object

private PKCS1 GetPKCS1Certificate()

{

PKCS1 res = null;

X509Certificate2 certificate = new X509Certificate2(@"..\..\licence\MyPFX.pfx", "toto", X509KeyStorageFlags.Exportable);

X509Store store1 = new X509Store(StoreName.My, StoreLocation.LocalMachine);

store1.Open(OpenFlags.ReadWrite);

store1.Add(certificate);

store1.Close();

bool check = certificate.HasPrivateKey;

byte[] pfxCertificate = certificate.Export(X509ContentType.Pkcs12, CertPwd);

MemoryStream memStream = new MemoryStream();

BinaryWriter binWriter = new BinaryWriter(memStream);

binWriter.Write(pfxCertificate);

memStream.Position = 0;

res = new PKCS1(memStream, CertPwd);

memStream.Position = 0;

return res;

}

Also, we will inform you regarding any further updation against your issue. As far as your license is concerned, you cannot use Aspose.Pdf for .NET license with Aspose.Pdf.Kit for .NET. Until the issue gets resolved, I think you can get a temporary license of Aspose.Total for .NET and use that for Aspose.Pdf.Kit for .NET. Once the issue gets resolved, you can use Aspose.Pdf for .NET license which you purchased.

Sorry for the inconvenience caused,

In the example (above), your development team are still reading the certificate from a file and not the keystore.


They are placing the certificate into the keystore using c#, but the X509Certificate2 object (certificate) is not read from the keystore, but from the pfx file.

Hi Matthew,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your feedback.

I would like to update you regarding your issue. Our development team is able to reproduce the issue at their end and the fix / update of this issue will be a part of our next release. You will be notified once the new release is available for download.

Sorry for the inconvenience caused,

nausherwan.aslam:

Hi Matthew,

Thank you for your feedback.

I would like to update you regarding your issue. Our development team is able to reproduce the issue at their end and the fix / update of this issue will be a part of our next release. You will be notified once the new release is available for download.

Sorry for the inconvenience caused,



Thank you. We are awaiting this fix as well. Do you have an Issue ID for it?

Hi Jay,

The issue is logged with an ID PDFNEWNET-30480 and its HotFix will be included in upcoming release version which is expected to be released by early October-2011. Please be patient and spare us little time.