Foxit PDF SDK

Public Member Functions | Static Public Attributes | List of all members
com.foxit.sdk.pdf.SignatureCallback Class Reference

## Public Member Functions
int | checkCertificateValidity (String cert_path, byte[] cert_password, java.lang.Object client_data)
| A callback function used to check the validity of a certificate. More...
int | continueCalcDigest (java.lang.Object client_data, PauseCallback pause)
| A callback function used to continue the custom digest calculation process. More...
byte [] | getDigest (java.lang.Object client_data)
| A callback function used to get the digest after the calculation process is finished. More...
boolean | isNeedPadData ()
| A callback function used to check whether to return all contents with padding zero or not, when callback function SignatureCallback.verifySigState is called. More...
void | release ()
| A callback function used to release current callback object itself. More...
byte [] | sign (byte[] digest, String cert_path, byte[] cert_password, int digest_algorithm, java.lang.Object client_data)
| A callback function used to do signing and return the signed data. More...
byte [] | sign (byte[] digest, StreamCallback cert_file_stream, byte[] cert_password, int digest_algorithm, java.lang.Object client_data)
| A callback function used to do signing and return the signed data. More...
boolean | startCalcDigest (FileReaderCallback file, int[] byte_range_array, Signature signature, java.lang.Object client_data)
| A callback function used to start a custom digest calculation, mainly to initialize the calculation process. More...
int | verifySigState (byte[] digest, byte[] signed_data, java.lang.Object client_data)
| A callback function used to verify the integrity of a signature and return the verify state. More...

## Static Public Attributes
static final int | e_CertCannotGetPrivateKey = 7
| Certificate's private key cannot be gotten.
static final int | e_CertDataError = 3
| Certificate's data is error.
static final int | e_CertExpired = 1
| Certificate is expired.
static final int | e_CertInvalidPassword = 4
| Certificate's password is wrong.
static final int | e_CertInvalidPath = 5
| Certificate's path is wrong.
static final int | e_CertNotSet = 6
| Certificate is not set to sign a signature.
static final int | e_CertUnsupportType = 2
| Certificate is unsupport type.
static final int | e_CertValid = 0
| Certificate is valid.

## Detailed Description

This class represent a callback object to sign or verify signature. All the pure virtual functions in this class are used as callback functions and should be implemented by user, in order to sign or verify signature in a customized way.
User can set register customized signature callback object to Foxit PDF SDK by function common.Library.registerSignatureCallback with filter and sub filter as the callback name.

See also
  com.foxit.sdk.common.Library

## Member Function Documentation

## ◆ checkCertificateValidity()

int com.foxit.sdk.pdf.SignatureCallback.checkCertificateValidity | ( | String | cert_path,
|  | byte [] | cert_password,
|  | java.lang.Object | client_data
| ) |  |

A callback function used to check the validity of a certificate.

This callback function will be triggered when function Signature.startSign is called. If no need to check the certificate, value com.foxit.sdk.pdf.SignatureCallback.e_CertValid can be returned directly.

Parameters

  [in] | cert_path | A full path of a certificate file (including file name and extension), which will be used for signing. This is passed by user from function Signature.startSign .
  [in] | cert_password | A password string used to open the cert file. If this is an empty string, that means no password is required.This is passed by user from function Signature.startSign .
  [in] | client_data | A user-defined object, which is passed by user from function Signature.startSign .

Returns
  Certificate validity. Please refer to values starting from com.foxit.sdk.pdf.SignatureCallback.e_CertValid and it should be one of these values.

## ◆ continueCalcDigest()

int com.foxit.sdk.pdf.SignatureCallback.continueCalcDigest | ( | java.lang.Object | client_data,
|  | PauseCallback | pause
| ) |  |

A callback function used to continue the custom digest calculation process.

Parameters

  [in] | pause | Pause object which decides if the calculation process needs to be paused. If this is null, it means not to pause during the calculation process. If this is not null, please check the the return value of function NeedToPauseNow() of this input parameter and decide when to pause the calculation process.
  [in] | client_data | A user-defined object, which is passed by user from function Signature.startSign or Signature.startVerify .

Returns
  com.foxit.sdk.common.Progressive.e_Finished means the calculation process has finished successfully.
  com.foxit.sdk.common.Progressive.e_ToBeContinued means the calculation process is not finished yet and callback function SignatureCallback.continueCalcDigest would be triggered again to continue the process.
  com.foxit.sdk.common.Progressive.e_Error means any error occurs.

## ◆ getDigest()

byte[] com.foxit.sdk.pdf.SignatureCallback.getDigest | ( | java.lang.Object | client_data | ) |

A callback function used to get the digest after the calculation process is finished.

This callback function will be triggered when the calculation process is finished successfully.

Parameters

  [in] | client_data | A user-defined object, which is passed by user from function Signature.startSign or Signature.startVerify .

Returns
  The digest string. If there is any error, please return an empty string.

## ◆ isNeedPadData()

boolean com.foxit.sdk.pdf.SignatureCallback.isNeedPadData | ( |  | ) |

A callback function used to check whether to return all contents with padding zero or not, when callback function SignatureCallback.verifySigState is called.

Returns
  true means to return all data in contents steam (including padding zero), while false means to return contents data without padding zero in stream end.

## ◆ release()

void com.foxit.sdk.pdf.SignatureCallback.release | ( |  | ) |

A callback function used to release current callback object itself.

Returns
  None.

## ◆ sign() [1/2]

byte[] com.foxit.sdk.pdf.SignatureCallback.sign | ( | byte [] | digest,
|  | String | cert_path,
|  | byte [] | cert_password,
|  | int | digest_algorithm,
|  | java.lang.Object | client_data
| ) |  |

A callback function used to do signing and return the signed data.

Host application provides this callback function for custom sign mechanism. This callback function would be triggered during the signature signing process.

Parameters

  [in] | digest | The digest data buffer, for source file buffer to be signed.
  [in] | cert_path | The certificate file path, which will be used for signing.
  [in] | cert_password | The password string, used to open the cert file. If this is an empty string, that means no password is required.
  [in] | digest_algorithm | The algorithm of message digest for signed data. Please refer to values starting from com.foxit.sdk.pdf.Signature.e_DigestSHA1 and this would be one of these values.
  [in] | client_data | A user-defined object, which is passed by user from function Signature.startSign or Signature.startVerify .

Returns
  Signed data. If there is any error, please return an empty string.
  The length of returned signed data should be within the default length of signature contents which is 7942 by default or specified by fucntion Signature.setDefaultContentsLength before signing the unsigned signature.

## ◆ sign() [2/2]

byte[] com.foxit.sdk.pdf.SignatureCallback.sign | ( | byte [] | digest,
|  | StreamCallback | cert_file_stream,
|  | byte [] | cert_password,
|  | int | digest_algorithm,
|  | java.lang.Object | client_data
| ) |  |

A callback function used to do signing and return the signed data.

Host application provides this callback function for custom sign mechanism. This callback function would be triggered during the signature signing process.

Parameters

  [in] | digest | The digest data buffer, for source file buffer to be signed.
  [in] | cert_file_stream | A com.foxit.sdk.common.fxcrt.StreamCallback object which is implemented by user to access content of a certificate file which will be used for signing.
  [in] | cert_password | The password string, used to open the cert file. If this is an empty string, that means no password is required.
  [in] | digest_algorithm | The algorithm of message digest for signed data. Please refer to values starting from com.foxit.sdk.pdf.Signature.e_DigestSHA1 and this would be one of these values.
  [in] | client_data | A user-defined object, which is passed by user from function Signature.startSign or Signature.startVerify .

Returns
  Signed data. If there is any error, please return an empty string.
  The length of returned signed data should be within the default length of signature contents which is 7942 by default or specified by fucntion Signature.setDefaultContentsLength before signing the unsigned signature.

## ◆ startCalcDigest()

boolean com.foxit.sdk.pdf.SignatureCallback.startCalcDigest | ( | FileReaderCallback | file,
|  | int [] | byte_range_array,
|  | Signature | signature,
|  | java.lang.Object | client_data
| ) |  |

A callback function used to start a custom digest calculation, mainly to initialize the calculation process.

Parameters

  [in] | file | When signing a signature, this represents the source file object to be signed. When verifying a signature field, this represents the source file object to be verified.
  [in] | byte_range_array | A byte range array of the signed document(not the source document). Elements in this array always be in pairs of offset-size values in order of: offset,size,offset,size...
  [in] | signature | A signature object.
  [in] | client_data | A user-defined object, which is passed by user from function Signature.startSign , Signature.startVerify .

Returns
  true means the calculation process is successfully started and then SignatureCallback.continueCalcDigest will be triggered to continue the calculation process. false means fail to start a calculation process.

## ◆ verifySigState()

int com.foxit.sdk.pdf.SignatureCallback.verifySigState | ( | byte [] | digest,
|  | byte [] | signed_data,
|  | java.lang.Object | client_data
| ) |  |

A callback function used to verify the integrity of a signature and return the verify state.

Host application provides this callback function for custom sign mechanism. This callback function would be triggered during the signature verifying process.
From 7.0, this callback function is only used to verify the intergrity of a signature. Please check the comment about return value for more details.

Parameters

  [in] | digest | The digest data buffer, for source file buffer to be verified.
  [in] | signed_data | The signed data buffer.
  [in] | client_data | A user-defined object, which is passed by user from function Signature.startSign or Signature.startVerify .

Returns
  Verify state:

  - Please return com.foxit.sdk.pdf.Signature.e_StateVerifyNoChange alone to indicate that the document has not been changed within the scope of the signature.

  - Otherwise, please return com.foxit.sdk.pdf.Signature.e_StateVerifyChange alone or combined with other error state value.