PdfSigner

object PdfSigner

JVM/Desktop-only digital signing of PdfKmp (or any) PDF bytes.

Signing applies an incremental update to the input bytes — the original content is left untouched and a signature dictionary plus the appended CMS/PKCS#7 detached signature are added at the end. This is the standard way to keep a PDF signature valid (the signed byte range covers everything except the signature value itself).

Two entry points:

  • sign with a (ByteArray) -> ByteArray callback — no BouncyCastle dependency. The caller computes the CMS detached signature over the supplied byte range however they like (an HSM, a remote signing service, their own BC code) and returns the DER-encoded SignedData. This is the recommended path for production: PdfKmp never touches the private key.

  • sign with a KeyStore / alias / password — a convenience that builds the CMS signature for you using BouncyCastle. BouncyCastle is a compileOnly dependency of PdfKmp (the ~9 MB jar is not bundled into the published artifact), so callers using this overload must add org.bouncycastle:bcpkix-jdk18on to their own runtime classpath. Calling it without BC on the classpath throws NoClassDefFoundError.

This is a JVM-only API and lives in jvmMain; there is no Android/iOS counterpart.

Functions

Link copied to clipboard
fun sign(pdfBytes: ByteArray, name: String? = null, reason: String? = null, location: String? = null, cmsSigner: (ByteArray) -> ByteArray): ByteArray

Signs pdfBytes using a caller-supplied CMS signing callback. No BouncyCastle dependency is involved on PdfKmp's side.

fun sign(pdfBytes: ByteArray, keyStore: KeyStore, alias: String, password: CharArray, reason: String? = null, location: String? = null): ByteArray

Convenience overload that builds the CMS signature with BouncyCastle from a KeyStore entry. Requires org.bouncycastle:bcpkix-jdk18on on the runtime classpath — see the class KDoc. Prefer the callback-based sign for production where the key lives in an HSM or a signing service.