> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chromiumly.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Security

> Encrypt, decrypt, sign, timestamp, and redact PDFs.

## Encrypt

`encrypt` protects the PDF with passwords. Set `userPassword`, `ownerPassword`, or both.

| Option | Type | Description |
| - | - | - |
| `userPassword` | `string` | The password to open the PDF |
| `ownerPassword` | `string` | The password that lifts the permissions |
| `algorithm` | `string` | `"aes256"` (default), `"aes128"`, `"rc4-128"` or `"rc4-40"` |
| `permissions` | `EncryptPermissions` | What a reader without the owner password may do |

`permissions` takes `print`, `printHighQuality`, `modifyContent`, `extractText`, `modifyAnnotations`, `fillForms` and `assemble`, each `true` unless you set it to `false`.

```typescript theme={null}
import { PDF } from "chromiumly";

const locked = await PDF.encrypt({
  files: ["path/to/report.pdf"],
  userPassword: "open-me",
  ownerPassword: "admin",
  permissions: { print: false, extractText: false },
});
```

As the last stage of a conversion:

```typescript theme={null}
import { UrlConverter } from "chromiumly";

const buffer = await new UrlConverter().convert({
  url: "https://example.com/",
  stages: [{ op: "encrypt", userPassword: "open-me" }],
});
```

Viewers enforce permissions; a tool that ignores them can still print. Only the user password keeps the content itself secret. Keep AES-256 unless an old reader can't open it.

Encryption comes last: only `optimize`, `render` and the extracts may follow it. A PDF/A or Factur-X can't be encrypted, and an encrypted PDF can't be signed — see the [order rules](https://docs.chromiumly.dev/stages.md#order-rules).

## Decrypt

`decrypt` opens encrypted PDFs and removes their encryption. In a list, it comes first.

```typescript theme={null}
const open = await PDF.decrypt({ files: ["path/to/locked.pdf"], password: "open-me" });
```

To only read an encrypted PDF, the read methods take a `password` instead, such as `PDF.info({ files, password })`.

## Sign

`sign` signs the PDF with a certificate you upload, so readers can check who signed it and that nothing changed since.

| Option | Type | Description |
| - | - | - |
| `certificate` | [`StageFile`](https://docs.chromiumly.dev/stages#files-a-stage-needs) | A PKCS#12 file (`.p12`, `.pfx`), or a PEM certificate with `key` (required) |
| `key` | `StageFile` | The PEM private key of a PEM `certificate` |
| `certificatePassword` | `string` | Opens a PKCS#12 `certificate` |
| `reason`, `location`, `contactInfo`, `name` | `string` | Shown in the viewer's signature panel |
| `pades` | `boolean` | A PAdES signature, the format the EU's eIDAS regulation recognizes (default `false`) |
| `timestampUrl` | `string` | An RFC 3161 timestamp authority to timestamp the signature with |

```typescript theme={null}
const signed = await PDF.sign({
  files: ["path/to/contract.pdf"],
  certificate: "path/to/company.p12",
  certificatePassword: "secret",
  reason: "Approved",
  pades: true,
});
```

A PEM pair works the same way:

```typescript theme={null}
const signed = await PDF.sign({
  files: ["path/to/contract.pdf"],
  certificate: "path/to/cert.pem",
  key: "path/to/key.pem",
});
```

Sign last: a change after a signature breaks it, so only `timestamp`, `render` and the extracts may follow `sign`. A stage that rewrites the file, such as `select`, `merge`, `remediate` or `optimize`, refuses a signed PDF. Stamps, rotations, metadata, bookmarks, attachments and tags append to the file and keep the signature.

An encrypted PDF signs in two requests: decrypt it, then sign the result.

## Timestamp

`timestamp` adds a document timestamp from an RFC 3161 timestamp authority: proof the PDF existed, unchanged, at that time. It names no signer; to timestamp a signature, give `sign` a `timestampUrl` instead.

```typescript theme={null}
const stamped = await PDF.timestamp({
  files: ["path/to/contract.pdf"],
  timestampUrl: "https://freetsa.org/tsr",
});
```

Gotenberg's operators decide which authorities it may call: see [Gotenberg – timestamp](https://gotenberg.dev/docs/pdf/timestamp#pick-the-authorities).

## Redact

`redact` removes the content under each region from the file itself, not just from view: the text is gone from the page and from any text a reader extracts. Nothing is drawn in its place.

Each region takes a `page`, and `x`, `y`, `width` and `height` in points from the bottom-left corner of the page.

```typescript theme={null}
const redacted = await PDF.pipe({
  files: ["path/to/report.pdf"],
  stages: [
    { op: "redact", regions: [{ page: 1, x: 72, y: 700, width: 200, height: 20 }] },
    // Optional: mark where content was, with a black box over the region
    { op: "stamp-image", image: "path/to/black.png", x: 72, y: 700, width: 200, height: 20, pages: "1" },
  ],
});
```

Redact first: a stamp only covers what's under it.

See [Reference — PDF](https://docs.chromiumly.dev/reference/pdf.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.