Unicode C
Unicode C
Sign PDF using PAdES-Baseline-B
See more PDF Signatures Examples
PAdES-Baseline-B is the most basic, entry-level profile of the PDF Advanced Electronic Signatures (PAdES) standard.
It means:
- A PDF contains a CMS/PKCS#7 detached signature over the document’s byte range.
/SubFiltermust beETSI.CAdES.detached.- The signer’s X.509 certificate is included inside the signature.
- The signature uses recognized secure algorithms (e.g., SHA-256 with RSA/ECDSA).
- It proves document integrity (no changes since signing) and signer authenticity (certificate identifies who signed).
- It does not include time-stamps, revocation data (CRL/OCSP), or long-term validation information — those appear only in higher levels (PAdES-Baseline-T, -LT, -LTA).
In short: Baseline-B = a standard PDF digital signature that ensures integrity and origin, but without time or revocation guarantees.
Chilkat Unicode C Downloads
#include <C_CkPdfW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkCertW.h>
void ChilkatSample(void)
{
BOOL success;
HCkPdfW pdf;
HCkJsonObjectW json;
HCkCertW cert;
const wchar_t *outFilePath;
success = FALSE;
pdf = CkPdfW_Create();
// Load a PDF to be signed.
success = CkPdfW_LoadFile(pdf,L"c:/someDir/my.pdf");
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
return;
}
// Options for signing are specified in JSON.
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"subFilter",L"/ETSI.CAdES.detached");
CkJsonObjectW_UpdateBool(json,L"signingCertificateV2",TRUE);
CkJsonObjectW_UpdateBool(json,L"signingTime",TRUE);
CkJsonObjectW_UpdateString(json,L"signingAlgorithm",L"pkcs");
CkJsonObjectW_UpdateString(json,L"hashAlgorithm",L"sha256");
// -----------------------------------------------------------
// The following JSON settings define the signature appearance.
CkJsonObjectW_UpdateInt(json,L"page",1);
CkJsonObjectW_UpdateString(json,L"appearance.y",L"top");
CkJsonObjectW_UpdateString(json,L"appearance.x",L"left");
CkJsonObjectW_UpdateString(json,L"appearance.fontScale",L"10.0");
CkJsonObjectW_UpdateString(json,L"appearance.text[0]",L"Digitally signed by: cert_cn");
CkJsonObjectW_UpdateString(json,L"appearance.text[1]",L"current_dt");
CkJsonObjectW_UpdateString(json,L"appearance.text[2]",L"Hello 123 ABC");
// --------------------------------------------------------------
// Load the signing certificate. (Use your own certificate.)
// Note: There are other methods for using a certificate on an HSM (smartcard or token)
// or from other sources, such as a cloud HSM, a Windows installed certificate,
// or other file formats.
cert = CkCertW_Create();
success = CkCertW_LoadPfxFile(cert,L"c:/myPfxFiles/myPdfSigningCert.pfx",L"pfxPassword");
if (success == FALSE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkCertW_Dispose(cert);
return;
}
// Once we have the certificate object, tell the PDF object to use it for signing
success = CkPdfW_SetSigningCert(pdf,cert);
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkCertW_Dispose(cert);
return;
}
// Sign the PDF, creating the output file.
outFilePath = L"c:/someDir/mySigned.pdf";
success = CkPdfW_SignPdf(pdf,json,outFilePath);
if (success == FALSE) {
wprintf(L"%s\n",CkPdfW_lastErrorText(pdf));
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkCertW_Dispose(cert);
return;
}
wprintf(L"Success.\n");
CkPdfW_Dispose(pdf);
CkJsonObjectW_Dispose(json);
CkCertW_Dispose(cert);
}