12/3/2023 0 Comments Itext digital signature example![]() ![]() ![]() X509CertificateParser parser = new X509CertificateParser() To do this, I used the classes provided from Bounc圜astle included in the package iTextSharp. It is then necessary to provide the PdfSignatureAppearance class with the certificate with the public key to be used for the signature. In this case a visible signature has been defined with a rectangle positioned in page 1. PdfSignatureAppearance sap = stamper.SignatureAppearance PdfStamper stamper = PdfStamper.CreateSignature(reader, ms, '\0') What we need next is the class PdfSignatureAppearance that takes care of the cryptographic options and appearances that form a signature. Using (MemoryStream ms = new MemoryStream()) using (PdfReader reader = new PdfReader(“HelloWorld.pdf”)) The first thing to do is to read the content of PDF to be signed this can be done simply by using the classes provided from iTextSharp. Usually this information is provided form the signature service, in the code, for simplicity, it is read from a certificate stored on filesystem. To be able to sign our document we need the public key of the certificate will be used to sign the document. The little I have found is also written in Java, so I thought of publishing an example of this implementation in C#.įor the realization of this solution I used the package iTextSharp v.5.5.13.1. There are a lot of examples in internet on how sign a PDF document, but very few on how sign the hash of a PDF document and recompose it. The result will be a document with a valid signature, without let the document get out from the company intranet. With a bit more complex implementation it is still possible to use the digital sign services while remaining adherent to corporate security policies the signature structure of PDF files allow to extract an hash of the document, sign it with the external service and recompose the PDF document with the signed hash. Sometimes the security policy of a company, doesn’t provide this type of behavior, making this solution unusable. However, this type of approach require that the caller has absolute trust to the service provider, because the document get out of the company intranet. The digital sign services assume that the document to be signed is sent to the service provider, who sign it and return it signed to the caller. This type of services have the undoubted advantage of allowing anyone to implement a digital sign solution in own company with a minimal impact, but sometimes they can present a security problem with company policies. The use of digital signatures is becoming more widespread and services that allow you to digitally sign documents are growing. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |