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
close icon

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

7 Replies

SL Sowmiya Loganathan Syncfusion Team 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 



EF Eugenio Favalli 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());




CM Chinnu Muniyappan Syncfusion Team 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 



EF Eugenio Favalli October 27, 2019 09:21 AM UTC

It DID work like a charm!
Thanks a lot


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

Hi Eugenio, 

Thank you for your update. 

Regards, 
Gowthamraj K 



RA Ricardo Abranches December 29, 2022 10:07 PM UTC

Hello

I'm trying to sign a pdf with a smartcard


I need to identify which certificate to use, which in this case is the serial number.


How can I do it ?

the password will be indicated below.

Attached is the example code.



Attachment: PdfAssinar_29027359.zip


IJ Irfana Jaffer Sadhik Syncfusion Team December 30, 2022 11:47 AM UTC

Use the below code snippet to get the certificates using the serial number:


Dim store As X509Store = New X509Store("MY", StoreLocation.CurrentUser)

store.Open(OpenFlags.[ReadOnly] Or OpenFlags.OpenExistingOnly)

Dim collection As X509Certificate2Collection = CType(store.Certificates, X509Certificate2Collection)

 Dim fcollection As X509Certificate2Collection = CType(collection.Find(X509FindType.FindBySerialNumber, "F85E1C5D93115CA3F969DA3ABC8E0E9547FCCF5A", True), X509Certificate2Collection)


Try this on your end and let us know the result.


Loader.
Live Chat Icon For mobile
Up arrow icon