Hi
I need to digitally sign (RSA and ECDSA) a PDF document using the PointCastle Library(https://pub.dev/packages/pointycastle).
Can anybody help me? Any sample code?
Thanks in advance
Hi Marcio,
As of now, We do not have support for signing PDF document by using PointCastle Library(https://pub.dev/packages/pointycastle). Currently, we are analyzing on this and we will update the further details on February 22nd 2022.
Refer to the following article to get more for signing a PDF document,
https://help.syncfusion.com/flutter/pdf/working-with-digital-signature
Regards,
Surya V
Surya
Thanks for your prompt response. As I could understand in the code sample for digital signature, you use PointCastle n the X.509 package. Am I correct ?
Thanks again
Regards
Hi Marcio,
No, We are not using PointyCastle for our digital signing process. As we said earlier, we are analyzing on this and we will update the further details on February 22nd 2022.
Regards,
Surya V
Hi Marcio,
We won’t be able to sign the PDF document directly using the pointycastle package but it is possible to use pointycastle package to generate signed bytes and externally sign the PDF document using the signature data.
Kindly use the following link for externally signing the PDF document, https://help.syncfusion.com/flutter/pdf/working-with-digital-signature#externally-sign-a-pdf-document
Kindly use the following code snippet for add signed data to PDF,
|
//Class for singing a PDF document externally. class PdfExternalSigner implements IPdfExternalSigner { //Hash algorithm. @override DigestAlgorithm get hashAlgorithm => DigestAlgorithm.sha256;
//Sign message digest. @override SignerResult sign(List<int> message) { final privateKey = _ InitializeRSAPrivateKey(); var signer = RSASigner(SHA256Digest(), '0609608648016503040201'); signer.init(true, PrivateKeyParameter<RSAPrivateKey>(privateKey)); List<int> signedBytes = signer.generateSignature(Uint8List.fromList(message)).bytes; return SignerResult(signedBytes); } }
PrivateKey InitializeRSAPrivateKey() { var rsapars = RSAKeyGeneratorParameters(BigInt.from(65537), 2048, 5); var secureRandom = FortunaRandom(); var random = Random.secure(); var seeds = <int>[]; for (var i = 0; i < 32; i++) { seeds.add(random.nextInt(255)); } secureRandom.seed(KeyParameter(Uint8List.fromList(seeds))); var params = ParametersWithRandom(rsapars, secureRandom); var keyGenerator = RSAKeyGenerator(); keyGenerator.init(params); return keyGenerator.generateKeyPair().privateKey; } |
Regards,
Surya V
Thanks, Surya
Can you please send an example using the above code? The document that you indicate uses a PFX file with a certificate and I don't have this file and I don't want to create this file?
Regards
Hi Marcio,
In Syncfusion Flutter PDF library, we won’t be able to externally sign a PDF document without valid certificate data. We have also attached a simple sample for externally signing PDF using some generated signed bytes from pointycastle package.
Kindly use the following package to download the sample, https://www.syncfusion.com/downloads/support/directtrac/general/ze/flutter_sample-517615916
Regards,
Surya V
Hi Surya V
Thanks for your reply. I am sorry for the delay but I was busy testing our solution .
Although I managed to sign the PDF Form using our PointCastle as directed by your post The signature file is not shown in the form. Everything works fine, no error, but the field is not shown.
Then I tested your code and it has the same behaviour.
Any Clue!
Best regards
Hi Marcio,
We recommend you enable the default set appearance of the form fields. Because few cases Form fields may appear empty in an adobe reader due to the absence of the appearance dictionary. To resolve this, you need to enable the Adobe Reader default appearance by using the setDefaultAppearance method in PdfForm class. Refer to the following UG documentation for more details, https://help.syncfusion.com/flutter/pdf/working-with-forms#troubleshooting and kindly try with the following code snippet and let us know the result,
|
document.form.setDefaultAppearance(true); |
Regards,
Surya V
Hi Surya
I inserted the code you suggested and I can see that there is a signature in the document. But no matter where a position the signature field it appears in the same location. Also when I show with the SfPdfViewer the signature des not appear at all!
Hi Marcio,
At present, our Flutter PDF Viewer doesn’t have support for digital signature. We have a workaround to viewing the existing digital signature in the PDF document, kindly refer to the following link,
https://www.syncfusion.com/downloads/support/directtrac/general/ze/annnotation-578168701.zip
We have logged a feature request for this support in the PDF document library. We do not have any immediate plans to implement these features and we will implement this support in any of our upcoming releases. We usually have an interval of at least three months between releases, at the planning stage for every release cycle, we review all open features. We will let you know when this feature is implemented.
Please find the feedback link to track the implementation of the feature below,
https://www.syncfusion.com/feedback/26234/support-for-digital-signature
Kindly refer to the below link for more information about preserving the existing annotation in Syncfusion Flutter PDFViewer
Regards,
Surya V
Hi Surya
Thanks for your replay.
The code didn't work for the digital signature in the PDF Viewer.
However, I can see, in Adobe Pdf Reader, that the signature is in the document but I can position the signature in the right place and the size of the signature shown in the document is truncated whatever the parameters I use in Rect.LTWH.
Hi Marcio,
|
The code didn't work for the digital signature in the PDF Viewer. |
Currently, We are analyzing on the requested sample and will update the further details on March 28, 2022.
|
|
However, I can see, in Adobe Pdf Reader, that the signature is in the document but I can position the signature in the right place and the size of the signature shown in the document is truncated whatever the parameters I use in Rect.LTWH.
myCripto = Cripto(); await myCripto!.fromSecureStorage(); final PdfSignatureField signatureField = await PdfSignatureField( page, 'Signature', bounds: Rect.fromLTWH(-65, 50, 200, 100));
|
We have checked the provided code snippet containing -65 in the left position(x-axis of page position). We recommend you use the positive values in the bounds(if the page and its graphics are in zero degrees) to get a better result. Eg: bounds: Rect.fromLTWH(65, 50, 200, 100));
|
Regards,
Surya V
Hi Surya, Thanks for your attention!
your suggestion :
"We have checked the provided code snippet containing -65 in the left position(x-axis of page position). We recommend you use the positive values in the bounds(if the page and its graphics are in zero degrees) to get a better result.
Eg: bounds: Rect.fromLTWH(65, 50, 200, 100));"
Does not work! The signature always appears at the same position no matter a change the Rect.fromLTWH's parameters. This seems to have no affect on the final PDF document.
Below some of the relevant code. Sorry I couldn't post the whole file.
Btw, all other elements appears on the right position.
Best regards
Hi Marcio,
We have prepared a sample to add digital signature in a specific coordinate with help of Syncfusion PDF and SfSignaturePad package. The sample can be downloaded from the following link.
https://www.syncfusion.com/downloads/support/directtrac/general/ze/pdfviewer_signature1106623277.zip
We tried to prepare the sample with the provided document, but the signature is not added and flatten while saving the PDFDocument. We are checking on this issue and will update the further details on 30 March 2022.
Regards,
Surya V
Hi Surya
Thanks for your reply!
I tried to run the sample in my computer and It didn't work. The digital signature is not shown. Only the image of the signature collected in the signature pad. I have tried many different approaches but had no success.
Best regards
Hi Marcio,
We have prepared the sample for adding signature in the existing PDF document(provided) and it can be downloaded from the following link,
We have also checked the reported issue in the workaround sample provided on 28 March, but the provided sample is working fine on our side. For your reference, we have prepared the output screen record of the sample, which can be downloaded from the following link,
https://www.syncfusion.com/downloads/support/directtrac/general/ze/Screenrecord-509618322.zip
Regards,
Deepika Ravi
Hi Deepika !
Thanks for you answer !
You same works with the signature pad. It shows the image of the hand signature. However the fields of the digital signature is not shown in the actual pdf form.
This field is not shown! I am trying to show the parameters of the field like location info, contact info and the image linked to the field.
Any idea why?
Best regards
Hi Marico,
Thank you for your update.
As mentioned earlier, SfPDFViewer doesn't provide support for digital signature. But as a workaround, we have flattened the signature and displayed it in PDFViewer. While flattening, the signature will be preserved as an image, and the signature's properties will be lost so the information like location, the contact won't be available in PDFViewer.
If the PDF document is saved without flattening, then the signature will be available in PDF form which can be viewed using an adobe pdf reader. Please find its code and screenshot.
Code Snippet:
|
final ByteData docBytes = await rootBundle.load("assets/aviso2.pdf");
|
Output Screenshot:
https://www.syncfusion.com/downloads/support/directtrac/general/SC1580~1-1684108337.png
Regards,
Deepika Ravi
Hi Deepika!
Thanks for your post! I have tried every sample you sent me and the signature is not shown. I Flatenned the fields and it shows the signature's image PDFViewer. If I don't flat the fields and try to show the document in Adobe and it also does not show the signature fields. I am stuck in on this. Below my last try:
Hi Marcio,
Thank you for your patience.
As of now, only the signed document appearance will be shown on the mobile reader and the signature details will not be shown, we have confirmed this behavior by signing PDF document using Adobe and ensured that the signature details were not shown in the mobile. If you want to show such details like signer, location, and more, you can draw it to the signature fields appearance(as in the below screenshot). Also we have confirmed that signature appearance is preserved properly in Adobe reader with and without flattening.
|
Adobe viewer mobile view |
|
|
Adobe viewer desktop view |
|
Kindly use the following sample for reference, https://www.syncfusion.com/downloads/support/directtrac/general/ze/pdfviewer_signature48823757-773381121428891908
Regards,
Anantha Gokula Raman J