What we need for signing a Pdf with Timestamp?
- pfx (PKCS12) file
- an exist Pdf file with random data (You can write a string inside the file like "Hello World") -- sha256.pdf
Install OpenSSL --> Download OpenSSL
Go OpenSSL Directory with 'cd' Command :
cd C:\Openssl\bin
C:\Openssl\bin\openssl.exe genrsa -out my_key.key 2048
C:\Openssl\bin\openssl.exe req -new -key my_key.key -out my_request.csr
C:\Openssl\bin\openssl.exe x509 -req -days 3650 -in my_request.csr -signkey my_key.key -out my_cert.crt
C:\Openssl\bin\openssl.exe pkcs12 -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -export -in my_cert.crt -inkey my_key.key -out my_pkcs12.pfx -name "my-name"
Change Files Directories and add TSA Client In Program.cs
const string originalPdfPath = @"C:\padestest\sha256.pdf"; // unsigned pdf file path (an existing pdf file)
const string finalPdfPath = @"C:\padestest\signed.pdf"; // output signed pdf file path
settings.SetTsaClient("http://timestamp.identrust.com/", "", "");
What is TSA Client?
We need TSA url, user id and password for add timestamp into our pdf file. There are many free TSA Client Servers for test --> Free Timestamp Servers
Add this line if you want see the signature in your pdf file:
appearance.SetVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
this will be the output :