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[]) {
if (argc < 6) {
print_sign_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
if (0 != strcmp(argv[0], "-s")) {
print_sign_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
if (0 != strcmp(argv[2], "-d")) {
print_sign_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
if (0 != strcmp(argv[4], "-k")) {
print_sign_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
source_document_path = argv[1];
destination_file_path = argv[3];
key_file = argv[5];
if (argc >= 7) {
if (0 != strcmp(argv[6], "-p")) {
print_sign_help();
return VANILLAPDF_TOOLS_ERROR_INVALID_PARAMETERS;
}
key_password = argv[7];
}
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;
}