Example use of digital signature with PKCS#12 key.
#include "tools.h"
void print_sign_help() {
printf("Usage: sign -s [source file] -d [destination file] -k [key file] -p [key password]");
}
int process_sign(int argc, char *argv[]) {
int arg_counter = 0;
for (arg_counter = 0; arg_counter < argc; ++arg_counter) {
if (strcmp(argv[arg_counter], "-s") == 0 && (arg_counter + 1 < argc)) {
source_document_path = argv[arg_counter + 1];
arg_counter++;
} else if (strcmp(argv[arg_counter], "-d") == 0 && (arg_counter + 1 < argc)) {
destination_file_path = argv[arg_counter + 1];
arg_counter++;
} else if (strcmp(argv[arg_counter], "-k") == 0 && (arg_counter + 1 < argc)) {
key_file = argv[arg_counter + 1];
arg_counter++;
} else if (strcmp(argv[arg_counter], "-p") == 0 && (arg_counter + 1 < argc)) {
key_password = argv[arg_counter + 1];
arg_counter++;
} else {
print_sign_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
}
if (source_document_path == NULL) {
print_sign_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
if (destination_file_path == NULL) {
print_sign_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
if (key_file == NULL) {
print_sign_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
RETURN_ERROR_IF_NOT_SUCCESS(
File_Create(destination_file_path, &destination_file));
RETURN_ERROR_IF_NOT_SUCCESS(
Document_Open(source_document_path, &source_document));
RETURN_ERROR_IF_NOT_SUCCESS(
Document_Sign(source_document, destination_file, signature_settings));
RETURN_ERROR_IF_NOT_SUCCESS(
File_Release(destination_file));
return VANILLAPDF_TOOLS_ERROR_SUCCESS;
}