DocumentProcessor

public final class DocumentProcessor

Class that describes all document operations.

  • Signs a document using the provided private key and certificate.

    The signature parameters must be specified in the options parameter. These options must contain the following fields:

    • DOCUMENT_SIGNATURE_FORMAT_KEY: A String indicating the signature format. Supported value is :
      • DOCUMENT_SIGNATURE_FORMAT_PKCS7 for PKCS#7 signature
    • DOCUMENT_HASH_ALGORITHM_KEY: A String indicating the hashing algorithm. Supported values are:
      • DOCUMENT_HASH_ALGORITHM_SHA1 for SHA-1 algorithm
      • DOCUMENT_HASH_ALGORITHM_SHA256 for SHA-256 algorithm
      • DOCUMENT_HASH_ALGORITHM_SHA384 for SHA-384 algorithm
      • DOCUMENT_HASH_ALGORITHM_SHA512 for SHA-512 algorithm

    Note: This options dictionary may evolve in the future to support additional parameters.

    Example:

    private let inputUIntData: [UInt8] = [0x49, 0x6E, 0x70, 0x75, 0x74, 0x20, 0x74, 0x65, 0x78, 0x74, 0x20, 0x66, 0x6F, 0x72, 0x20, 0x43, 0x61, 0x44, 0x45, 0x53, 0x20, 0x73, 0x69, 0x67, 0x6E, 0x20, 0x74, 0x65, 0x73, 0x74, 0x2E]
    let inputData = Data(inputUIntData)
    let options: [String: Any] = [
     DocumentProcessor.DOCUMENT_SIGNATURE_FORMAT_KEY : DocumentProcessor.DOCUMENT_SIGNATURE_FORMAT_PKCS7,
     DocumentProcessor.DOCUMENT_HASH_ALGORITHM_KEY : DocumentProcessor.DOCUMENT_HASH_ALGORITHM_SHA256
    ]
    let signedDocument = OutputStream.toMemory()
    DocumentProcessor.signDocument(
        documentStream: InputStream(data: inputData),
        privateKey: privateKey!,
        certificat: certificate!,
        options: options,
        signedDocumentStream: signedDocument
    ) { error in
        if error != nil {
            // an error occurred
        }
        else {
            // signature is successful
        }
    }
    

    Declaration

    Swift

    public static func signDocument(
    	documentStream: InputStream,
    	privateKey: PrivateKey,
    	certificate: Certificate,
    	options: [String: Any],
    	signedDocumentStream: OutputStream,
    	completionHandler: @escaping (_ error: NSError?) -> Void
    )

    Parameters

    documentStream

    An InputStream containing the raw document to sign.

    privateKey

    A PrivateKey object used to perform the signature.

    certificate

    A Certificate object matching the private key, with appropriate usage for digital signature.

    options

    A [String: Any] providing signature configuration as described above.

    signedDocumentStream

    An OutputStream where the signed document will be written.

    completionHandler

    Called when the signing operation is complete.

    • error NSError?: nil if signing was successful; otherwise, an error object describing the failure.