Utilities

CosSignFile

The CosSignFile dll (cossignfile.dll) allows to sign from Cosmos documents in PDF, XML and binary format, as well as XML files of electronic invoice in FacturaE format, using a digital certificate. This certificate must be installed on the system in a certificate store (file).

CosSignFile uses the JAVA libraries included in the FacturaE software, which is a free software developed in the Java language. For this reason, it is necessary that a 32-bit Java virtual machine be installed on the system and that the directory where is located the JVM.DLL file be included in the search path.

This utility is available as of version 7.2 of Cosmos.

Functions exported by CosSignFile dllIr al principio de la página

The steps to follow to sign a document from Cosmos are the following:

  1. Run the CosSignFileCreateSigner function to obtain a handler that allows us to execute the functions necessary to carry out the signature process.
  2. Obtain the literals corresponding to the values of the properties of the document to be signed (certificate store format, signature algorithm, signature format, signature mode). The values of these properties can be obtained by invoking the functions:
    1. CosSignFileGetKeystoreFormats
    2. CosSignFileGetSignAlgorithms
    3. CosSignFileGetPAdESSignFormats
    4. CosSignFileGetCAdESSignFormats
    5. CosSignFileGetXAdESSignFormats
    6. CosSignFileGetSignModes
  3. Execution of the signature process with the call to the corresponding function (CosSignFileSignFacturaE, CosSignFileSignPDF, CosSignFileSignPAdES, CosSignFileSignXAdES, CosSignFileSignCAdES).
  4. Release of the resources used during the signature process with the execution of the CosSigFileFreeSigner function.

CosSignFileCreateSigner

This function returns a unique numerical identifier that will be necessary for the execution of the signature property assignment functions and for the signature process itself.

CosSignFileFreeSigner

This function will release the resources of the signature handler sent as a parameter.

After executing this function, the identifier passed as a parameter can’t be used again to sign a document. A new identifier must be created by executing the CosSignFileCreateSigner function.

CosSignFileSignFacturaE

This function will sign in FacturaE format the XML file passed as a parameter.

CosSignFileSignPDF

This function will sign the PDF file passed as a parameter.

CosSignFileSignPAdES

This function will sign the PDF file passed as a parameter using the PAdES format (PDF Advanced Electronic Signatures).

CosSignFileSignXAdES

This function will sign the XML file passed as a parameter using the format XAdES (XML Advanced Electronic Signatures).

CosSignFileSignCAdES

This function will sign the file passed as a parameter using the CAdES (CMS Advanced Electronic Signatures) format.

CosSignFileGetKeystoreFormats

This function allows to query the list of possible types of certificate stores supported by the API.

CosSignFileGetSignAlgorithms

This function allows to query the list of possible encryption algorithms supported by the API.

CosSignFileGetPAdESSignFormats

This function allows to query the list of possible PAdES signature formats supported by the API.

CosSignFileGetCAdESSignFormats

This function allows to query the list of possible CAdES signature formats supported by the API.

CosSignFileGetXAdESSignFormats

This function allows to query the list of possible XAdES signature formats supported by the API.

CosSignFileGetSignModes

This function allows to query for the list of possible signature modes supported by the API.

Log FileIr al principio de la página

The CosSignFile.dll DLL allows the creation of an operations log in Log4Java format by defining the log4j.properties file in the directory where the CosSignFile.dll file is located.

Example:

# Root logger option
log4j.rootLogger=INFO, stdout, file

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=c:/tmp/log4j-cosmoSigner.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

In the attribute "log4j.rootLogger" the level of log is indicated. The possible values are ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE and WARN.

The attribute "log4j.appeder.file.File" will indicate the path of the log file.

For more information, consult the Log4j documentation at the following address: https://logging.apache.org/log4j.

Considerations about file pathsIr al principio de la página

The CosSignFile.dll DLL makes use of a series of classes programmed in the Java language to perform the process of signing XML, PDF and binary files. For this reason, the paths of the signature files, XML files, PDF files and binary files must have the "/" character as the directory separator, instead of the Microsoft Windows "\".

ExamplesIr al principio de la página

In PDF document you can see the following examples::