Rust
Rust
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 Rust Downloads
let pdf = chilkat::Pdf::new();
// Load a PDF to be signed.
if pdf.load_file("c:/someDir/my.pdf").is_err() {
println!("{}", pdf.last_error_text());
return;
}
// Options for signing are specified in JSON.
let json = chilkat::JsonObject::new();
let _ = json.update_string("subFilter", "/ETSI.CAdES.detached");
let _ = json.update_bool("signingCertificateV2", true);
let _ = json.update_bool("signingTime", true);
let _ = json.update_string("signingAlgorithm", "pkcs");
let _ = json.update_string("hashAlgorithm", "sha256");
// -----------------------------------------------------------
// The following JSON settings define the signature appearance.
let _ = json.update_int("page", 1);
let _ = json.update_string("appearance.y", "top");
let _ = json.update_string("appearance.x", "left");
let _ = json.update_string("appearance.fontScale", "10.0");
let _ = json.update_string("appearance.text[0]", "Digitally signed by: cert_cn");
let _ = json.update_string("appearance.text[1]", "current_dt");
let _ = json.update_string("appearance.text[2]", "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.
let cert = chilkat::Cert::new();
if cert.load_pfx_file("c:/myPfxFiles/myPdfSigningCert.pfx", "pfxPassword").is_err() {
println!("{}", cert.last_error_text());
return;
}
// Once we have the certificate object, tell the PDF object to use it for signing
if pdf.set_signing_cert(&cert).is_err() {
println!("{}", pdf.last_error_text());
return;
}
// Sign the PDF, creating the output file.
let out_file_path = "c:/someDir/mySigned.pdf".to_string();
if pdf.sign_pdf(&json, &out_file_path).is_err() {
println!("{}", pdf.last_error_text());
return;
}
println!("Success.");