es.caib.signatura.api
Interface Signer

All Known Implementing Classes:
CAIBSigner

public interface Signer

Interface to abstract signing and verifying implementations of diferent certificate entities. Generated signatures are detached (doesn't include signed data) and can have timestamp. Signatures are encapsulated into Signature objects.

Version:
1.0
Author:
Jesús Reyes (3dígits)
See Also:
Signature

Field Summary
static int PDF_SIGN_DEFAULT_SIGNATURE_APPERANCE
          Indica que se añadirá una estampa por defecto de adobe, en vez del código de puntos PDF417.
static int PDF_SIGN_PAGE_LAST
          Indica que sólo se añadirá en la última página
static int PDF_SIGN_PDF417_SIGNATURE_APPERANCE
           
static int PDF_SIGN_POSITION_BOTTOM
          Indicates that the signature will be added in the bottom part of the PDF document.
static int PDF_SIGN_POSITION_LEFT
          Indicates that the signature will be added in the left part of the PDF document.
static int PDF_SIGN_POSITION_NONE
          Neither code bars nor signer information will be added to the PDF document.
static int PDF_SIGN_POSITION_RIGHT
          Indicates that the signature will be added int the right part of the PDF document.
static int PDF_SIGN_POSITION_TOP
          Indicates that the signature will be added in the upper part of the PDF document.
 
Method Summary
 void certifyDigitalCopy(java.io.InputStream contentStream, java.io.OutputStream signedStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String url, java.lang.String localidad, float x, float y, float rotation)
          Firma digitalmente de un documento PDF pasado como InputStream y devuelve el mismo PDF firmado y modificado de forma que, en uno de los bordes del documento que se le indique, aparezca el firmante que compulsa la copia, la url desde la que se puede consultar el PDF y una matriz de puntos en formato PDF417 que continene esa misma URL.
 void generateSMIME(java.io.InputStream document, Signature signature, java.io.OutputStream smime)
          Generates SMIME document from the document and its digital signature.
 void generateSMIMEParalell(java.io.InputStream document, Signature[] signatures, java.io.OutputStream smime)
          Obtiene el documento SMIME a partir del documento original y el conjunto de firmas digitales obtenidas de firmas el documento.
 java.lang.String getAPIVersion()
          Gets the API version number.
 java.lang.String[] getCertList(java.lang.String contentType)
          Gets the available certificate names list to the API: hard disk, USB devices, cryptographic cards, etc.
 java.util.Date getCurrentDate(java.lang.String certificateName, java.lang.String password, java.lang.String contentType)
          Obtiene la hora oficial que tendría un sello de tiempo generado en ese mismo instante
 SMIMEParser getSMIMEParser(java.io.InputStream smime)
          Returns an SMIMEParser object to access to the SMIME document information.
 ParsedCertificate parseCertificate(java.security.cert.X509Certificate certificateChain)
          Returns basic certificate information.
 Signature sign(java.io.InputStream contentStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType)
          Gets the digital signature of an input data stream and encapusulates it into a Signature object without timestamp.
 Signature sign(java.lang.String fileName, java.lang.String certificateName, java.lang.String password, java.lang.String contentType)
          Gets the digital signature of a hard disk document and encapsulates it into a signature object without timestamp.
 Signature sign(java.net.URL url, java.lang.String certificateName, java.lang.String password, java.lang.String contentType)
          Signs a document obtained from an URL.
 void signPDF(java.io.InputStream contentStream, java.io.OutputStream signedStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String url, int position)
          Signs a document obtained from an URL.
 void signPDF(java.io.InputStream contentStream, java.io.OutputStream signedStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String url, int position, boolean allowMultipleSignature)
          Signs a PDF document.
 void signPDF(java.io.InputStream pdfInputStream, java.io.OutputStream signedStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String textoAdicional, int stampOptions, float top, float left, float height, float width, float rotation, boolean allowMultipleSignature)
          Firma digitalmente de un documento PDF pasado como InputStream y devuelve el mismo PDF firmado y modificado.
 java.io.OutputStream signPDF(java.io.InputStream contentStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String url, int position)
          Deprecated.  
 java.io.OutputStream signPDF(java.io.InputStream contentStream, java.lang.String certificateName, java.lang.String password, java.lang.String contentType, java.lang.String url, int position, boolean allowMultipleSignature)
          Deprecated.  
 boolean verify(java.io.InputStream contentStream, Signature signatureData)
          Verifies the digital signature of a document obtained from an URL.
 boolean verify(java.lang.String fileName, Signature signatureData)
          Verifies the digital signature of a document contained into the hard disk.
 boolean verify(java.net.URL url, Signature signatureData)
          Verifies the digital signature of a document obtained from an URL.
 boolean verifyAPosterioriTimeStamp(java.io.InputStream contentStream, Signature signatureData)
          Verifies the signature of an input data stream.
 boolean verifyAPosterioriTimeStamp(java.lang.String fileName, Signature signatureData)
          Verifies the digital signature of an input data stream.
 boolean verifyAPosterioriTimeStamp(java.net.URL url, Signature signatureData)
          Verifies the digital signature of a document obtained from an URL.
 

Field Detail

PDF_SIGN_POSITION_TOP

static final int PDF_SIGN_POSITION_TOP
Indicates that the signature will be added in the upper part of the PDF document.

See Also:
Constant Field Values

PDF_SIGN_POSITION_BOTTOM

static final int PDF_SIGN_POSITION_BOTTOM
Indicates that the signature will be added in the bottom part of the PDF document.

See Also:
Constant Field Values

PDF_SIGN_POSITION_LEFT

static final int PDF_SIGN_POSITION_LEFT
Indicates that the signature will be added in the left part of the PDF document.

See Also:
Constant Field Values

PDF_SIGN_POSITION_RIGHT

static final int PDF_SIGN_POSITION_RIGHT
Indicates that the signature will be added int the right part of the PDF document.

See Also:
Constant Field Values

PDF_SIGN_POSITION_NONE

static final int PDF_SIGN_POSITION_NONE
Neither code bars nor signer information will be added to the PDF document.

See Also:
Constant Field Values

PDF_SIGN_PAGE_LAST

static final int PDF_SIGN_PAGE_LAST
Indica que sólo se añadirá en la última página

See Also:
Constant Field Values

PDF_SIGN_DEFAULT_SIGNATURE_APPERANCE

static final int PDF_SIGN_DEFAULT_SIGNATURE_APPERANCE
Indica que se añadirá una estampa por defecto de adobe, en vez del código de puntos PDF417.

See Also:
Constant Field Values

PDF_SIGN_PDF417_SIGNATURE_APPERANCE

static final int PDF_SIGN_PDF417_SIGNATURE_APPERANCE
See Also:
Constant Field Values
Method Detail

getCertList

java.lang.String[] getCertList(java.lang.String contentType)
                               throws SignatureCertNotFoundException,
                                      SignaturePrivKeyException
Gets the available certificate names list to the API: hard disk, USB devices, cryptographic cards, etc.

Returns:
the names of the available certificates.
Throws:
SignatureCertNotFoundException - if no available certificates.
SignaturePrivKeyException - if unable to access to private keys.

sign

Signature sign(java.lang.String fileName,
               java.lang.String certificateName,
               java.lang.String password,
               java.lang.String contentType)
               throws java.io.IOException,
                      SignatureException
Gets the digital signature of a hard disk document and encapsulates it into a signature object without timestamp.

Parameters:
fileName - path of the document.
certificateName - name of the certificate used to sign the document.
password - private key password of the certificate.
contentType - MIME type of the document to sign.
Returns:
Signature the document signature.
Throws:
java.io.FileNotFoundException - if unable to find the document.
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
java.security.UnrecoverableKeyException - if the private key password is not correct.
SignatureException - if any signature error occurs.

sign

Signature sign(java.io.InputStream contentStream,
               java.lang.String certificateName,
               java.lang.String password,
               java.lang.String contentType)
               throws java.io.IOException,
                      SignatureException
Gets the digital signature of an input data stream and encapusulates it into a Signature object without timestamp.

Parameters:
contentStream - data stream to sign.
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
Returns:
Signature the signature of the data stream.
Throws:
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
java.security.UnrecoverableKeyException - if the private key password is not correct.
SignatureException - if any signature error occurs.

signPDF

void signPDF(java.io.InputStream contentStream,
             java.io.OutputStream signedStream,
             java.lang.String certificateName,
             java.lang.String password,
             java.lang.String contentType,
             java.lang.String url,
             int position)
             throws java.io.IOException,
                    SignatureException
Signs a document obtained from an URL.

Parameters:
url - URL address where is located the document to sign.
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
Throws:
java.io.FileNotFoundException - if original file not found.
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
java.security.UnrecoverableKeyException - if the private key password is not correct.
SignatureException - if any signature error occurs.

signPDF

void signPDF(java.io.InputStream contentStream,
             java.io.OutputStream signedStream,
             java.lang.String certificateName,
             java.lang.String password,
             java.lang.String contentType,
             java.lang.String url,
             int position,
             boolean allowMultipleSignature)
             throws java.io.IOException,
                    SignatureException
Signs a PDF document. In one of the borders of the document appears the signer's certificate name, an URL where the PDF document can be downloaded and a bar code in PDF417 format that codifies the url.

Parameters:
contentStream - data stream to sign.
signedStream - resulting signed data stream.
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
url - URL to add to the document.
position - Position in each page of the document where the URL will be added. The possible values are: PDF_SIGN_POSITION_TOP, PDF_SIGN_POSITION_BOTTOM, PDF_SIGN_POSITION_RIGHT o PDF_SIGN_POSITION_LEFT.
allowMultipleSignature - allow to sign an already signed PDF
Throws:
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
java.security.UnrecoverableKeyException - if the private key password is not correct.
SignatureException - if any signature error occurs.

signPDF

java.io.OutputStream signPDF(java.io.InputStream contentStream,
                             java.lang.String certificateName,
                             java.lang.String password,
                             java.lang.String contentType,
                             java.lang.String url,
                             int position)
                             throws java.io.IOException,
                                    SignatureException
Deprecated. 

Signs a PDF document and returns the signed PDF document. In one of the borders of the document appears the signer's certificate name, an URL where the PDF document can be downloaded and a bar code in PDF417 format that codifies the url.

Parameters:
contentStream - data stream to sign.
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
url - URL to add to the document.
position - Position in each page of the document where the URL will be added. The possible values are: PDF_SIGN_POSITION_TOP, PDF_SIGN_POSITION_BOTTOM, PDF_SIGN_POSITION_RIGHT o PDF_SIGN_POSITION_LEFT.
Returns:
the signed PDF document.
Throws:
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
java.security.UnrecoverableKeyException - if the private key password is not correct.
SignatureException - if any signature error occurs.

signPDF

java.io.OutputStream signPDF(java.io.InputStream contentStream,
                             java.lang.String certificateName,
                             java.lang.String password,
                             java.lang.String contentType,
                             java.lang.String url,
                             int position,
                             boolean allowMultipleSignature)
                             throws java.io.IOException,
                                    SignatureException
Deprecated. 

Signs a PDF document and returns the signed PDF document. In one of the borders of the document appears the signer's certificate name, an URL where the PDF document can be downloaded and a bar code in PDF417 format that codifies the url.

Parameters:
contentStream - data stream to sign.
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
url - URL to add to the document.
position - Position in each page of the document where the URL will be added. The possible values are: PDF_SIGN_POSITION_TOP, PDF_SIGN_POSITION_BOTTOM, PDF_SIGN_POSITION_RIGHT o PDF_SIGN_POSITION_LEFT.
allowMultipleSignature - allow to sign an already signed PDF
Returns:
the signed PDF document.
Throws:
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
java.security.UnrecoverableKeyException - if the private key password is not correct.
SignatureException - if any signature error occurs.

signPDF

void signPDF(java.io.InputStream pdfInputStream,
             java.io.OutputStream signedStream,
             java.lang.String certificateName,
             java.lang.String password,
             java.lang.String contentType,
             java.lang.String textoAdicional,
             int stampOptions,
             float top,
             float left,
             float height,
             float width,
             float rotation,
             boolean allowMultipleSignature)
             throws java.io.IOException,
                    SignatureException
Firma digitalmente de un documento PDF pasado como InputStream y devuelve el mismo PDF firmado y modificado. Las opciones de firma PDF estan establecidas en la clase Signer.

Parameters:
pdfInputStream -
signedStream -
certificateName - Nombre del certificado obtenido de la llamada a Signer.getCertList()
password - contraseña de la clave privada del usuario
contentType - tipo MIME del documento a firmar
textoAdicional - URL en caso de estampado PDF417, o motivo de firma para firmas con estampado ABODE
stampOptions - Opciones de firma PDF definidas en la clase Signer
top - El 0 corresponde al borde inferior del documento.
left - El 0 corresponde al borde izquierdo del documento
height - Anchura máxima de la estampa, el texto de dividirà en las líneas necesarias para que quepa en la anchura establecida.
width - Altura máxima de la estampa. Debe tenerse en cuenta que si la altura no es suficientemente grande para el texto que se divide en múltiples líneas, este se corta y desaparece.
rotation - Sólo permite rotación la firma con estampado PDF417. En caso de rotación el estampado se rotarà desde la esquina inferior izquierda (top, left).
allowMultipleSignature - Permitir o no refirmado del documento PDF si el documento de entrada ya está firmado
Throws:
java.io.IOException
SignatureException

certifyDigitalCopy

void certifyDigitalCopy(java.io.InputStream contentStream,
                        java.io.OutputStream signedStream,
                        java.lang.String certificateName,
                        java.lang.String password,
                        java.lang.String contentType,
                        java.lang.String url,
                        java.lang.String localidad,
                        float x,
                        float y,
                        float rotation)
                        throws java.io.IOException,
                               SignatureException
Firma digitalmente de un documento PDF pasado como InputStream y devuelve el mismo PDF firmado y modificado de forma que, en uno de los bordes del documento que se le indique, aparezca el firmante que compulsa la copia, la url desde la que se puede consultar el PDF y una matriz de puntos en formato PDF417 que continene esa misma URL.

Parameters:
contentStream -
signedStream -
certificateName -
password -
contentType -
url -
localidad -
x -
y -
rotation -
Throws:
java.io.IOException
SignatureException

sign

Signature sign(java.net.URL url,
               java.lang.String certificateName,
               java.lang.String password,
               java.lang.String contentType)
               throws java.io.IOException,
                      SignatureException
Signs a document obtained from an URL.

Parameters:
url - URL address where is located the document to sign.
certificateName - certificate name to use.
password - private key password of the certificate to use.
contentType - MIME type of the document to sign.
Returns:
Signature the signature of the document.
Throws:
java.io.FileNotFoundException - if original file not found.
java.io.IOException - if I/O errors occurs.
SignatureProviderException - if unable to access to the signature API needed provider.
SignatureSignException - if an error occurs at signing process.
java.security.UnrecoverableKeyException - if the private key password is not correct.
SignatureException - if any signature error occurs.

verifyAPosterioriTimeStamp

boolean verifyAPosterioriTimeStamp(java.io.InputStream contentStream,
                                   Signature signatureData)
                                   throws SignatureProviderException,
                                          java.io.IOException,
                                          SignatureVerifyException
Verifies the signature of an input data stream. If the digital signature requires a timestamp and don't have it then a timestamp is added (if possible).

Parameters:
contentStream - data stream of the original document.
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.

verifyAPosterioriTimeStamp

boolean verifyAPosterioriTimeStamp(java.net.URL url,
                                   Signature signatureData)
                                   throws SignatureProviderException,
                                          java.io.IOException,
                                          SignatureVerifyException
Verifies the digital signature of a document obtained from an URL. If the digital signature requires a timestamp and don't have it then a timestamp is added (if possible).

Parameters:
url - URL of the original document.
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.

verifyAPosterioriTimeStamp

boolean verifyAPosterioriTimeStamp(java.lang.String fileName,
                                   Signature signatureData)
                                   throws SignatureProviderException,
                                          java.io.IOException,
                                          SignatureVerifyException
Verifies the digital signature of an input data stream. If the digital signature requires a timestamp and don't have it then a timestamp is added (if possible).

Parameters:
fileName - path of the original document.
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.

verify

boolean verify(java.io.InputStream contentStream,
               Signature signatureData)
               throws SignatureProviderException,
                      java.io.IOException,
                      SignatureVerifyException
Verifies the digital signature of a document obtained from an URL. If the digital signature requires a timestamp and don't have it then a timestamp is added (if possible).

Parameters:
url - URL address where is located the original document.
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.

verify

boolean verify(java.lang.String fileName,
               Signature signatureData)
               throws java.io.FileNotFoundException,
                      SignatureProviderException,
                      java.io.IOException,
                      SignatureVerifyException
Verifies the digital signature of a document contained into the hard disk. If the digital signature requires a timestamp and don't have it then a timestamp is added (if possible).

Parameters:
fileName - path of the original document.
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
java.io.FileNotFoundException - if original file not found.
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.

verify

boolean verify(java.net.URL url,
               Signature signatureData)
               throws SignatureProviderException,
                      java.io.IOException,
                      SignatureVerifyException
Verifies the digital signature of a document obtained from an URL. The verification process is independent of signature timestamp.

Parameters:
url - URL address where is located the original document.
signatureData - signature to verify.
Returns:
true if the verification is correct; false otherwise.
Throws:
java.io.FileNotFoundException - if original file not found.
SignatureProviderException - if unable to access to the signature API needed provider.
java.io.IOException - if the document or the timestamp server is not available.
SignatureVerifyException - if an error occurs at verifying process.

generateSMIME

void generateSMIME(java.io.InputStream document,
                   Signature signature,
                   java.io.OutputStream smime)
                   throws java.io.IOException
Generates SMIME document from the document and its digital signature.

Parameters:
smime - output stream to write the generated SMIME document.
signature - digital signature of the document.
document - input stream of the original document.
Throws:
java.io.IOException - if I/O errors occurs.

generateSMIMEParalell

void generateSMIMEParalell(java.io.InputStream document,
                           Signature[] signatures,
                           java.io.OutputStream smime)
                           throws java.io.IOException,
                                  SignatureException
Obtiene el documento SMIME a partir del documento original y el conjunto de firmas digitales obtenidas de firmas el documento.

Parameters:
document - InputStream con el documento que se firmó
signatures - firmas digital del documento
smime - OutputStream con el SMIME obtenido
Throws:
java.io.IOException
SignatureException

getCurrentDate

java.util.Date getCurrentDate(java.lang.String certificateName,
                              java.lang.String password,
                              java.lang.String contentType)
                              throws SignatureTimestampException,
                                     SignatureException,
                                     java.io.IOException
Obtiene la hora oficial que tendría un sello de tiempo generado en ese mismo instante

Parameters:
certificateName - nombre del certificado que se usará para firmar
password - contraseña de la clave privada del usuario
contentType - tipo MIME del documento a firmar
Returns:
Hora Oficial
Throws:
java.io.IOException
SignatureException
SignatureTimestampException

getAPIVersion

java.lang.String getAPIVersion()
Gets the API version number.

Returns:
the API version number;

getSMIMEParser

SMIMEParser getSMIMEParser(java.io.InputStream smime)
                           throws java.io.FileNotFoundException,
                                  java.lang.InstantiationException,
                                  java.lang.IllegalAccessException,
                                  java.io.IOException,
                                  SignatureException
Returns an SMIMEParser object to access to the SMIME document information.

Parameters:
smime - the SMIME document to read.
Returns:
an SMIMEParser object to access to the SMIME document information.
Throws:
java.io.FileNotFoundException - if smime file not found.
java.lang.InstantiationException - if problems instanciating the SMIMEParserObject.
java.lang.IllegalAccessException - if problems instanciating the SMIMEParserObject.
java.io.IOException - if I/O errors occurs.
SignatureException - if any signature error occurs.

parseCertificate

ParsedCertificate parseCertificate(java.security.cert.X509Certificate certificateChain)
Returns basic certificate information.

Parameters:
certificate - Certificat to parse.
Returns:
Parsed certificate.


Copyright © 2011 Direcció General de Tecnologia i Comunicacions. Govern de les Illes Balears. All Rights Reserved.