Digitally signing a document
Digitally signing a document
Hello,
A PDF-document can be signed digitally in Acrotbat Reader.
But does anyone know how I can check in my FWH-application if a PDF-document has been signed digitally?
Thank you in advance.
A PDF-document can be signed digitally in Acrotbat Reader.
But does anyone know how I can check in my FWH-application if a PDF-document has been signed digitally?
Thank you in advance.
Last edited by driessen on Mon Apr 15, 2024 7:06 am, edited 1 time in total.
Regards,
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
- Antonio Linares
- Site Admin
- Posts: 42270
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Digital signing a document
Dear Michel,
Asking chatgpt:
you can utilize a C library that provides PDF parsing capabilities. One such library is Poppler, which is widely used for working with PDF files in C
You can download the pre-built Poppler library for Windows from the Poppler website: https://poppler.freedesktop.org/.
Here is the code to check for the signature:
We can easily adap that code to Harbour or simply build an EXE from it and run it
Asking chatgpt:
you can utilize a C library that provides PDF parsing capabilities. One such library is Poppler, which is widely used for working with PDF files in C
You can download the pre-built Poppler library for Windows from the Poppler website: https://poppler.freedesktop.org/.
Here is the code to check for the signature:
Code: Select all | Expand
#include <stdio.h>
#include <poppler-document.h>
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <input_pdf>\n", argv[0]);
return 1;
}
const char *input_pdf = argv[1];
GError *error = NULL;
// Open the PDF document
PopplerDocument *document = poppler_document_new_from_file(input_pdf, NULL, &error);
if (error != NULL) {
fprintf(stderr, "Error opening PDF: %s\n", error->message);
g_error_free(error);
return 1;
}
// Check if the document is encrypted
if (poppler_document_get_n_pages(document) == 0) {
printf("The PDF is encrypted.\n");
} else {
printf("The PDF is not encrypted.\n");
}
// Check if the document is signed
if (poppler_document_get_metadata(document, "signature") != NULL) {
printf("The PDF is signed.\n");
} else {
printf("The PDF is not signed.\n");
}
// Free the document object
g_object_unref(document);
return 0;
}
Re: Digital signing a document
Antonio,
I'm afraid that is somewhat to difficult for me.
I need to know if a document is digitally signed or not.
But I don't know how to implement your suggestion.
I'm afraid that is somewhat to difficult for me.
I need to know if a document is digitally signed or not.
But I don't know how to implement your suggestion.
Regards,
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Re: Digital signing a document
Can you please send a link here a sample digitally signed pdf?driessen wrote:Antonio,
I'm afraid that is somewhat to difficult for me.
I need to know if a document is digitally signed or not.
But I don't know how to implement your suggestion.
Regards,
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
Hakan ONEMLI
Harbour & MSVC 2022 & FWH 23.04
- Antonio Linares
- Site Admin
- Posts: 42270
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Digital signing a document
Much simpler
Use this function:
Use this function:
Code: Select all | Expand
#include "FiveWin.ch"
function Main()
MsgInfo( IsSigned( "fwintro.pdf" ) )
return nil
function IsSigned( cPDFFileName )
return At( "/SigFlags", hb_memoRead( cPDFFileName ) ) != 0
Re: Digital signing a document
Antonio,
Thanks a lot for your help.
I'll test it tonight or tomorrow.
Have a fine Sunday.
Thanks a lot for your help.
I'll test it tonight or tomorrow.
Have a fine Sunday.
Regards,
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Re: Digital signing a document
Antonio,
Unfortunately, I always get a .F. as result, whether it is signed or not.
Unfortunately, I always get a .F. as result, whether it is signed or not.
Regards,
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
- Antonio Linares
- Site Admin
- Posts: 42270
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Digital signing a document
Dear Michel,
Then I guess your PDFs are encrypted
Could you please email me one of them ? thanks
Then I guess your PDFs are encrypted
Could you please email me one of them ? thanks
Re: Digital signing a document
Antonio,
I just send you a PDF-file which I digitally signed.
The PDF-file was made by saving as a PDF-file in Word.
Thanks.
I just send you a PDF-file which I digitally signed.
The PDF-file was made by saving as a PDF-file in Word.
Thanks.
Regards,
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
- Antonio Linares
- Site Admin
- Posts: 42270
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Digitally signing a document
Dear Michel,
I got it, thank you
Do you also need to know information about the signature ?
I got it, thank you
Do you also need to know information about the signature ?
Re: Digitally signing a document
No, I just need to know if the document is digitally signed or not.
Regards,
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Re: Digitally signing a document
FYI, Antonio,
If I use "Michel" in stead of "/SigFlags", I get a .T.
If I use "Michel" in stead of "/SigFlags", I get a .T.
Regards,
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
- Antonio Linares
- Site Admin
- Posts: 42270
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Digitally signing a document
Dear Michel,
The simplest way I have found to build a tool to check if a PDF is signed is using python.
signed.py
Using pyinstaller we can create a standalone EXE:
Here you have it:
https://wormhole.app/QoPx3#Ze8o1phu14n66ZQUwCH6TA
You can call it from FWH using:
Unfortunately signed.exe size is large but it works fine
The simplest way I have found to build a tool to check if a PDF is signed is using python.
signed.py
Code: Select all | Expand
import sys, aspose.pdf as ap
pdfSign = ap.facades.PdfFileSignature()
pdfSign.bind_pdf(sys.argv[ 1 ])
signatures = pdfSign.get_sign_names( True )
if( signatures.length ) > 0 :
print( "signed" )
else:
print( "not signed" )
Using pyinstaller we can create a standalone EXE:
Code: Select all | Expand
pyinstaller --onefile signed.py
https://wormhole.app/QoPx3#Ze8o1phu14n66ZQUwCH6TA
You can call it from FWH using:
Code: Select all | Expand
WaitRun( "signed.exe " + cPdfFileName + " > result.txt" )
if hb_memoRead( "result.txt" ) == "signed"
MsgInfo( "signed" )
else
MsgInfo( "non signed" )
endif
-
- Posts: 172
- Joined: Tue Oct 18, 2005 10:01 am
Re: Digitally signing a document
Hi, maybe you can test with chilkat:
https://www.example-code.com/foxpro/pdf_signatures.asp
Regards,
Toninho.
https://www.example-code.com/foxpro/pdf_signatures.asp
Regards,
Toninho.
- Antonio Linares
- Site Admin
- Posts: 42270
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Digitally signing a document
Great web for examples!
thank you
thank you