Hi, I have a problem that is driving me crazy.
I have a client that needs to digitally sign a PDF that is generated by their website, using their CAC card.
I was attempting to do this by using CAPICOM with javascript to export the certificate, and get their certificate server-side. After doing this however, I get an error stating "Private key not exist in the certificate" when I try to use the exported certificate to sign a document. I am currently testing this using the John Doe certificate that came with the example.
Is there anyway to fix this problem? Being able to digitally sign the pdf documents that we keep on the server is important to their workflow, but I haven't figured out a way to sign the documents server-side yet.
Thanks in advance
Signing a PDF from Website
Re: Signing a PDF from Website
Support · Oct 9, 2008Hello,
The certificate can contain a private and/or public key. In order to sign the PDF document the certificate must contain the private key.
You may have to pass the private key to the server to be able to sign the PDF document and this may not be even possible. You may have to check with the organization if that’s allowed.
Thanks,
ceTe Software Support Team
Re: Signing a PDF from Website
Forum member · Oct 9, 2008They are fine with me passing the private key, the problem is I haven't been able to get the certificate with the private key to the server.
When I use CAPICOM to export the certificate, it apparently exports it without the private key. I can get the private key, and pass it seperatley, but I don't know how to merge them back together on the server-side.
Do you have any ideas how I can take a byte array of the certificate, and a string for the private key and merger them together before I call the sign method on the document object?
Thanks in advance.
Re: Signing a PDF from Website
Support · Oct 9, 2008Hello,
You may be able to merge them together by following the steps below. We have not tested this so we are not sure if that will work.
1. Use the X509Certificate2 class of System.Security.Cryptography.X509Certificates Namespace to bring in the data you get from CAPICOM. It's a .NET class.
2. Set the private key using the PrivateKey property.
3. Use ContentType.Pkcs7 when you use the Export method to export the certificate.
4. Then use the certificate within our product to sign the document.
Please post a response letting us know if the above steps worked. In the mean time we will also check with the developers to see if they have any further suggestions.
Thanks,
ceTe Software Support Team
Re: Signing a PDF from Website
Forum member · Oct 9, 2008Thanks for the help.
The problem I am currently having is while I have access to the private key client-side I can't figure out a way to get the private key object server-side.
With the certificate itself I am able to something like below to get a base64 encoded string to the server. Once on the server I convert it to a byte array, then import it into the certificate object. As of yet I am not sure how I can serialize/deserialize the private key object.
==== client-side ====
<input id="clientCert" name="clientCert" type="hidden" />
<script type="text/javascript">
CurrentUserStore = new ActiveXObject('CAPICOM.Store');
CurrentUserStore.Open(CAPICOM_CURRENT_USER_STORE);
certs = CurrentUserStore.Certificates.Select();
cert = certs.Item(1);
privateKey = certs.Item(1).PrivateKey; // not sure what to do with this
document.getElementById("clientCert").value = cert.Export();
</script>
==== On Server ====
Dim c As New X509Certificate2 c.Import(Convert.FromBase64String(Request.Form("clientCert")))
c.PrivateKey = ??? 'This is where I am stuck
On a side not when I changed how I am getting the byte array of the certificate on the server-side to the method you described, my exception message changed. The exception I get now is "The specified network password is not correct."
Re: Signing a PDF from Website
Support · Oct 9, 2008Hello,
You will likely have to send the private key along with the certificate to the server side and then add the private key to the certificate.
Other option that may work, would be to save the certificate using the Save method. That saves the private key also and then upload or stream the saved file to the server from the clients machine.
Thanks,
ceTe Software Support Team