sign

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.

Return

the signed PDF bytes (original content + incremental signature).

Parameters

pdfBytes

the PDF to sign.

name

optional signer name written into the signature dictionary.

reason

optional human-readable reason for signing.

location

optional signing location.

cmsSigner

produces the DER-encoded CMS/PKCS#7 detached signature over the bytes it is handed (the document's signed byte range). The input is the content to sign; the output is the SignedData.


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.

Return

the signed PDF bytes.

Parameters

pdfBytes

the PDF to sign.

keyStore

key store holding the signing key + certificate chain.

alias

entry alias of the private key.

password

password protecting the key entry.

reason

optional human-readable reason for signing.

location

optional signing location.