Giter Site home page Giter Site logo

evandroabreu / java-digital-signature Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alessioscarfone/java-digital-signature

0.0 0.0 0.0 50.96 MB

Java command line tool for digital signature with PKCS#11 token.

License: GNU General Public License v3.0

Java 100.00%

java-digital-signature's Introduction

Java-Digital-Signature

Java command line tool for digital signature with PKCS#11 token.

To use the tool simply run signer.jar.

# help
> java -jar signer.jar -h

Usage: PKCS#11 Digital Signature Tool [options] [command] [command options]
  Options:
    -h, --help
      display help
    -d, --driver
      PKCS#11 Driver
    -p, --password
      Pass password in command line (USE WITH CAUTION)
    -u, --key-usage
      show key usage
      Default: false
    -i, --info-certificates
      show certificates info
      Default: false
  Commands:
    cades      CAdES signature format
      Usage: cades [options] FileToSign
        Options:
          -h, --help
            display help
          -c, --choose-certificate
            choose certificate to use
          -o, --output-folder
            set destination FOLDER for the output file
          -n, --newfile-name
            set name of the new file

    pades      PAdES signature format
      Usage: pades [options] FileToSign
        Options:
          -h, --help
            display help
          -c, --choose-certificate
            choose certificate to use
          -o, --output-folder
            set destination FOLDER for the output file
          -n, --newfile-name
            set name of the new file
          -v, --visible-signature
            add visible signature - only text
            Default: false
          -vi, --visible-signature-image
            add visible signature - text and image
          -s, --skip-field-selection
            skip the choice of the field to use
            Default: false
          -f, --field-to-sign
            name of the field to sign
          -pg, --page
            page of signature  [If a field is selected this option is ignored]
            Default: 1
          -pv, --vertical-signature-position
            vertical position of visible signature: T(op) - M(iddle) -
            B(ottom) [If a field is selected this option is ignored]
          -ph, --horizontal-signature-position
            horizontal position of visible signature: L(eft) - C(enter) -
            R(ight) [If a field is selected this option is ignored]


Usage example

Token Info:

List all certificates and show purpose of the public key contained in each certificate (key usage).

>java -jar signer.jar -u

Password:
<certificate name>
Certificate: <i>
Key Usage:
 digitalSignature => false
 nonRepudiation => true
 keyEncipherment => false
 dataEncipherment => false
 keyAgreement => false
 keyCertSign => false
 cRLSign => false
 encipherOnly => false
 decipherOnly => false

For more detailed info use -i option.

The jar contain the driver used for the token in use (see NOTE section at the end of the Readme) and auto extract it, in the same folder of the jar, at the first run.

It is possible to use a specific driver with the -d option.

CAdES (CMS Advanced Electronic Signatures):

# Basic usage:
>java -jar signer.jar cades test.pdf
Selected Signature Format: CADES
Start Signature Procedure
Password:

Certificate to use:  <certificate name>
Start of signing process...
Create signed file: test.pdf.p7m
End of signing process.

It is possible to specify folder and name of the output file with -o and -n options:

>java -jar signer.jar cades test.pdf -o Test -n newfile.pdf

PAdES (PDF Advanced Electronic Signatures):

  • No visible signature
>java -jar signer.jar pades test.pdf
Selected Signature Format: PADES
Start Signature Procedure
Password:

Certificate to use:  <certificate name>
No available field in the pdf.
Start of signing process...
Create signed file: test-signed.pdf
End of signing process.
  • Visible signature (-v option or -vi for use also an image). If the pdf contains some signable fields, the tool asks to user if he wants to use one of them, else the signature is placed in the lower left corner of the first page. The position of the signature can be customized using the options -pg, -pv, -ph (page, vertical postion, horizontal position)
>java -jar signer.jar pades -v test.pdf
[...]

Certificate to use: <certificate name>
No available field in the pdf.
Start of signing process...
Create signed file: test-signed(1).pdf
End of signing process.

>java -jar signer.jar pades -v test-form.pdf -pg 2 -pv T -ph R
[....]

# Put Signature in the top right corner of the second page of the pdf

  • Try to sign a document that contains signable fields:
>java -jar signer.jar pades -v test-form.pdf                                                      
[...]
Certificate to use: <certificate name> 
[0] - page:1 - Signature
[1] - page:1 - Signature_1
[2] - page:2 - Signature_2
Select Field to use (-1 or Enter for skip):0
[....]   

In this way the field named 'Signature' was used for contain the signature. If the field name is already known, it can be provided with -f option. For skip this step use -s option.

>java -jar signer.jar pades -v test-form.pdf -f Signature

NB: if a field is selected, all placement options (-pg, -pv, -ph) are ignored.


Dependencies:


NOTE:

Token Image

java-digital-signature's People

Contributors

alessioscarfone avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.