Skip to content

Free dotNetCore library for digitaly sign pdf files with X509 certificates. This library is a dot net core wrapper on JSignPdf java application.

Notifications You must be signed in to change notification settings

eyal7773/DotNetCore-DigitalSignaturePdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DotNetCore-DigitalSignaturePdf

Free dotNetCore library for digitaly sign pdf files with X509 certificates. This library is a dot net core wrapper on JSignPdf java application. This library already include JSignPdf inside. You can use this library by using nuget package, or by clone this repo and compile by yourself.

be aware! java need to be installed on your server to use this library. I added links for windows & linux later.

Install

Just add this nuget packege to your project. DigitalSignPdf Nuget Package

  • By Package Manager :
Install-Package DigitalSignPdf -Version 1.0.0 
  • By dotnet cli :
dotnet add package DigitalSignPdf --version 1.0.0 

How to use

            Signer signer = new Signer("D:\\Temp\\", "C:\\Program Files\\Java\\jdk1.8.0_152\\bin\\java.exe");

            string fileAsBase64String = Convert.ToBase64String(System.IO.File.ReadAllBytes("C:\\temp\\basic.pdf"));


            string signedFileBase64String = signer.Sign(fileAsBase64String
                                            , "C:/TEMP/cert/eyal-cert.pfx",
                                            "password",
                                            "");

Detailed Explain

  • Create instance of Signer class. You need to supply :
    • (1) Temporary folder (full permissions needed).
    • (2) full path to the java bin file.
  • Now prepare base 64 string from your pdf.
  • To sign your pdf , use Sign method. You need to supply :
    • (1) base 64 string of your pdf.
    • (2) full path to your X509 certificate (pfx file).
    • (3) password to your pfx file - if needed (if not, supply empty string).
    • (4) Password for the signed pdf that will be return. (if you don't want to lock the pdf with a password - supply empty string).

After Build(=compile) the project (or by using the nuget package) - the assets folder will be copied to your lib/.../publish folder - this folder is crucial because it contains the JSignPdf app.

Need to generate self sign certificate ?

Here are the commands ( you need openssl - it is installed by default on most linux distributions, and for windows you can use openssl for Windows ).

If it is your first time you create certificate, just know, that you will be asked for some identification details (Country, city, FQDN = your domain, etc.). Answer these questions as you want. Just remmber that if someone will look on the pdf signature details - these are the details that he/she will see.

  • First - create new certificate.
openssl req -x509 -days 365 -newkey rsa:2048 -keyout my-key.pem -out my-cert.pem
  • Next - convert the certificate to single pfx file
openssl pkcs12 -export -in my-cert.pem -inkey my-key.pem -out eyal-cert.pfx

Links to install java

  • As said before you need java to be installed (JDK).

Licenses

JSignPdf is released under Mozilla Public License (version 1.1 or later) and GNU LGPL (version 2.1 or later). So this library also use the same licences.

About

Free dotNetCore library for digitaly sign pdf files with X509 certificates. This library is a dot net core wrapper on JSignPdf java application.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages