We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Calculate PDF Digest from Cert

I’m trying to use aspose pdf with a certificate signing service. They only provide me the OSCP and certificate and ca cert, not the private key. The interface for the PdfFileSignature.sign seems to require a pfx which in turn requires a private key. Is there any way around this? Does aspose pdf provide a way to calculate a digest using an X509 certificate and then allow me to inject a signed cert into the document?

Well, the password is required to access X.509 certificate data. Aspose.Pdf API does not support creation of signature objects (PKCS1, PKCS7, etc) with passing X509Certificate2. It applies as input parameter PFX files only. You can try to convert X509 Certificate2 object into PFX object using the following code snippet:


PKCS1 res = null;
// Read from file works fine
// res = new PKCS1(@"C:\Users\lonesheep\Documents\tmp\cert\pkcs10.pfx", "toto");

// ...what I want to do is get the pfx from the local keystore and create the PKCS1 from a stream
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
X509Certificate2Collection certCollection =
store.Certificates.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
X509Certificate2Enumerator enumerator = certCollection.GetEnumerator();
X509Certificate2 cert = null;
while (enumerator.MoveNext())
    if (enumerator.Current.FriendlyName.CompareTo("someFriendlyname") == 0)
        cert = enumerator.Current;

byte[] pkcs10 = cert.Export(X509ContentType.Pfx, "toto");
MemoryStream memStream = new MemoryStream();
BinaryWriter binWriter = new BinaryWriter(memStream);
memStream.Position = 0;
res = new PKCS1(memStream, "toto");