We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

FileFormats PDF - Digital signature by SmartCard

Thread ID:

Created:

Updated:

Platform:

Replies:

148505 Oct 22,2019 09:26 AM UTC Oct 28,2019 05:42 AM UTC WinForms 5
loading
Tags: PDF
Eugenio Favalli
Asked On October 22, 2019 09:26 AM UTC

Hi,
I downloaded the FileFormats PDF nuget package for trial, I have a couple of questions:

1) simple, where do I put the license key (trial now), but commercial later?
2) is it possible to digitally sign a pdf using a certificate in the smartcard without using the windows store?

Thanks

Sowmiya Loganathan [Syncfusion]
Replied On October 23, 2019 01:06 PM UTC

Hi Eugenio, 

Thank you for contacting Syncfusion support. 

where do I put the license key (trial now), but commercial later?  
Please refer the below help link to include the generated license key in Windows Forms application. 


 

Refer to the below link which will direct you to generate the Syncfusion license key.  


Is it possible to digitally sign a pdf using a certificate in the smartcard without using the windows store?  
We can able to sign PDF document with external signature using X509Certficate2. Please refer the below KB link for more details, 

Please let us know if you need any further assistance on this. 


Regards, 
Sowmiya Loganathan 


Eugenio Favalli
Replied On October 23, 2019 08:51 PM UTC

Hi, I've read and tested the example

But I’m still unable to get if it’s possible to achieve my aim to digitally sign a pdf with a smart card.

 

I modified the sample to use my certificate as below:

 

        private static void Signature_ComputeHash(object sender, PdfSignatureEventArgs arguments)

        {

            //Get the document bytes

            byte[] documentBytes = arguments.Data;

 

            SignedCms signedCms = new SignedCms(new ContentInfo(documentBytes), detached: true);

 

            //Compute the signature using the specified digital ID file and the password

            //X509Certificate2 certificate = new X509Certificate2("DigitalSignatureTest.pfx", "DigitalPass123");

 

            //var cmsSigner = new CmsSigner(certificate);

            var cmsSigner = new CmsSigner(selectedCertificate);

            //Set the digest algorithm SHA256

 

            cmsSigner.DigestAlgorithm = new Oid("2.16.840.1.101.3.4.2.1");

 

            signedCms.ComputeSignature(cmsSigner);

 

            //Embed the encoded digital signature to the PDF document

            arguments.SignedData = signedCms.Encode();

        }

 

 

where selectedCertificate is the certificate on the smartcard, I can use it to encrypt custom data and I get prompted to insert my PIN:

 

var privateKey = cert.PrivateKey;

var hardwareDevice = rsa.CspKeyContainerInfo.HardwareDevice;

 

if (hardwareDevice) // sure - smartcard

{

  string secret = "secret text";

  byte[] unsigned = Encoding.UTF8.GetBytes("secret text");

  byte[] signed = rsa.SignData(new MemoryStream(unsigned), new System.Security.Cryptography.SHA256CryptoServiceProvider());



Chinnu Muniyappan [Syncfusion]
Replied On October 25, 2019 09:29 AM UTC

Hi Eugenio, 
 
We have support to sign a  PDF document using X509Certiticate2 with/without exportable private key. Based on your code we found that if you can able to retrieve the X509Certificate2 instance from the smartcard, then we can sign this using the following code.  
 
//Load the PDF document. 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); 
 
//Load the existing page. 
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; 
 
//Create PDF certificate with X509Certicate2 object. 
PdfCertificate certifiate = new PdfCertificate(cert /* x509 certificate retrieved from smartcard */); 
 
PdfSignature signature = new PdfSignature(loadedDocument, page, certifiate, "Sig1"); 
 
signature.Bounds = new RectangleF(0, 0, 200, 100); 
 
//Save and close the PDF document. 
loadedDocument.Save(“output.pdf"); 
 
loadedDocument.Close(true); 
 
Kindly try this in your side and let us know whether its achieves your requirement.  
  
Regards, 
Chinnu M 


Eugenio Favalli
Replied On October 27, 2019 09:21 AM UTC

It DID work like a charm!
Thanks a lot

Gowthamraj Kumar [Syncfusion]
Replied On October 28, 2019 05:42 AM UTC

Hi Eugenio, 

Thank you for your update. 

Regards, 
Gowthamraj K 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon