# eGov Validation Client SDK

The eGov Validation Client SDK provides Java classes to use as a client for the eGov validation service.

## Requirements

### Java Runtime Environment

The target Java runtime version for the validation client library is 17.

### Security Provider

The validation client SDK uses the SHA-256 hash algorithm, which is not available from the default Java security provider. To use the validation client SDK, install a security provider that provides the SHA-256 hash algorithm, such as the Bouncycastle security provider.

### Logging

The validation client SDK uses SLF4J for logging. To get logging output from the validation client SDK, make sure you have a usable SLF4J backend.

## API examples

### Validating all signatures in a file

This example assumes that

- the variable `pdfFile` contains a `File` object pointing to a PDF file on disk,
- that the variable `client` contains a `String` specifying the "client" property to use to validate the file,
- and that the variable `serviceUrl` contains a `String` specifying the base URL of the validation service server.

    FileRequest fileRequest = new FileRequest(pdfFile, client);
    ValidationServiceClient serviceClient = ValidationServiceClientBuilder.newBuilder() //
    		.serviceUrl(serviceUrl) //
    		.build();
    ValidationResponse response = serviceClient.validateOneRequest(Arrays.asList(fileRequest), false, null, null, "de", null);

### Validating a single signature in a file

This example assumes that

- the variable `pdfBytes` contains a `byte[]` object representing a PDF file,
- that the variable `client` contains a `String` specifying the "client" property to use to validate the file,
- that the variable `sigName` contains a `String` specifying the name of a signature field in the PDF,
- and that the variable `serviceUrl` contains a `String` specifying the base URL of the validation service server.

    ValidationServiceClient serviceClient = ValidationServiceClientBuilder.newBuilder() //
    		.serviceUrl(serviceUrl) //
    		.build();
    ValidationResponse response = serviceClient.validateOneSignature(pdfBytes, client, false, sigName,
    		"file.pdf", null, null, "de", null);

### Creating a validation report

This example assumes that

- the variable `pdfFile` contains a `File` object pointing to a PDF file on disk,
- that the variable `client` contains a `String` specifying the "client" property to use to validate the file,
- and that the variable `serviceUrl` contains a `String` specifying the base URL of the validation service server.

    FileRequest fileRequest = new FileRequest(pdfFile, client);
    ValidationServiceClient serviceClient = ValidationServiceClientBuilder.newBuilder() //
    		.serviceUrl(serviceUrl) //
    		.build();
    ValidationResponse response = serviceClient.validateOneRequest(Arrays.asList(fileRequest), true, null, null, "de", "report.pdf");
    File file = new File(response.getPdfOutputFileName());
    try (OutputStream stream = new FileOutputStream(file)) {
    	stream.write(response.getPdfReport());
    }

### Validating all signatures in a batch of files

This example assumes that

- the variables `pdfFile1` and `pdfFile2` contain `File` objects pointing to PDF files on disk,
- that the variable `client` contains a `String` specifying the "client" property to use to validate the file,
- and that the variable `serviceUrl` contains a `String` specifying the base URL of the validation service server.

    FileRequest fileRequest1 = new FileRequest(pdfFile1, client);
    FileRequest fileRequest2 = new FileRequest(pdfFile2, client);
    ValidationServiceClient serviceClient = ValidationServiceClientBuilder.newBuilder() //
    		.serviceUrl(serviceUrl) //
    		.build();
    ValidationResponse response = serviceClient.validateOneRequest(Arrays.asList(fileRequest1, fileRequest2), false, null, null, "de", null);

## API reference

The API reference for the validation client SDK is provided via Javadoc.