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. Image for the cookie policy date

FileFormats PDF - Digital signature by SmartCard

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

5 Replies

SL Sowmiya Loganathan Syncfusion Team October 23, 2019 08:06 AM

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 



EF Eugenio Favalli October 23, 2019 03:51 PM

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());




CM Chinnu Muniyappan Syncfusion Team October 25, 2019 04:29 AM

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 



EF Eugenio Favalli October 27, 2019 04:21 AM

It DID work like a charm!
Thanks a lot


GK Gowthamraj Kumar Syncfusion Team October 28, 2019 12:42 AM

Hi Eugenio, 

Thank you for your update. 

Regards, 
Gowthamraj K 


Loader.
Live Chat Icon For mobile
Up arrow icon