Save Certificates

Hello
Does Aspose PDF allow extraction of x509 certificates used to sign the PDF documents?
If so is there a sample snippet?
And what’s the usual release day of PDF’s new builds?
Thanks :slight_smile:

@australian.dev.nerds

Please try using the below code snippet and in case you face any issues, please let us know:

using (Document pdfDocument = new Document(dataDir + "DSC Signed.pdf"))
{
    foreach (Field field in pdfDocument.Form)
    {
        SignatureField sf = field as SignatureField;
        if (sf != null)
        {
            Signature s = sf.Signature;
            var date = s.Date;
            var location = s.Location;
            var reason = s.Reason;
            SignatureCustomAppearance signatureapp = s.CustomAppearance;
            Stream cerStream = sf.ExtractCertificate();
            PKCS7 pKCS7 = new PKCS7(cerStream, "");
            if (cerStream != null)
            {
                using (cerStream)
                {
                    byte[] bytes = new byte[cerStream.Length];
                    using (FileStream fs = new FileStream(dataDir + @"input.cer", FileMode.CreateNew))
                    {
                        cerStream.Read(bytes, 0, bytes.Length);
                        fs.Write(bytes, 0, bytes.Length);
                    }
                }
            }
        }
    }
}
1 Like

Thanks, will test this converted vb.net code and will let you know:

Using pdfDocument As Document = New Document(dataDir.ToString() & “DSC Signed.pdf”)
For Each field As Field In pdfDocument.Form
Dim sf As SignatureField = TryCast(field, SignatureField)
If sf IsNot Nothing Then
Dim s As Signature = sf.Signature
Dim [date] = s.[Date]
Dim location = s.Location
Dim reason = s.Reason
Dim signatureapp As SignatureCustomAppearance = s.CustomAppearance
Dim cerStream As Stream = sf.ExtractCertificate()
Dim pKCS7 As PKCS7 = New PKCS7(cerStream, “”)
If cerStream IsNot Nothing Then
Using cerStream
Dim bytes = New Byte(cerStream.Length - 1) {}
Using fs As FileStream = New FileStream(dataDir.ToString() & “input.cer”, FileMode.CreateNew)
cerStream.Read(bytes, 0, bytes.Length)
fs.Write(bytes, 0, bytes.Length)
End Using
End Using
End If
End If
Next
End Using

Btw, why not internally use X509Certificate2Collection Class to store individual certificates in X509Certificate2 Classes?

@australian.dev.nerds

We need to investigate this feasibility. Therefore, an investigation ticket has been logged as PDFNET-55289 in our issue tracking system. We will look into its details and let you know as soon as it is resolved.

We are sorry we missed it in our first response. The usual release time is mid of the month. However, this may not be promising because sometimes, integration tests and other release process may take more time than expected due to newly incorporated features and enhancements. However, we do announce the release in our forums for fixed issues and requirements. Please feel free to let us know in case you have further inquireis.

1 Like

Thanks, just found that Words will not load Pdf under .net framework 4.0 (full profile) projects.
What about Pdf? Supports loading Pdf files in .net fw 4.0, no need to modify pdf files in anyway, just need to convert them to Rtf or Html or Mhtml etc…?

@australian.dev.nerds

Yes, Aspose.PDF for .NET supports .NET 4.0 Framework. However, we removed support for .NET 4.0 Client Profile recently. You can please try using it to load and convert PDF files. In case you face any issues, please let us know.