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

> ## Agent Instructions
> Bach builds Windows installers from one bach.toml with the bach command: bach init, bach check, bach preview, bach build. Installs are per user and need no administrator rights by default. installer.scope = "machine" installs for every user after one Windows prompt. On Windows, run setup files with Start-Process -Wait -PassThru in PowerShell, and give signtool arguments that start with the word sign.

# Protect a paid or private app with access keys

> Require a key before installing, encrypt the packaged files, give each customer their own key and keep updates private. Know what it can't protect.

If your app is only for paying customers or a private group, the installer can ask for an access key and encrypt your files with it. This page shows how to set it up, what your users see, and the limits of this protection.

## Turn it on

```toml bach.toml theme={"theme":{"light":"github-light","dark":"github-dark"}}
[access]
get_key_url = "https://example.com/buy"
```

`get_key_url` is optional. It adds a **Get a key** button to the key page.

## Make keys and build

Keys are never written into `bach.toml`. Make one:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
bach key --out keys.txt
bach build --key-file keys.txt
```

`keys.txt` holds a random key. Send it to your customer. Keep the file private and out of Git. Instead of a file, you can put one key into the `BACH_ACCESS_KEY` environment variable.

To give every customer their own key, make many at once:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
bach key --count 100 --out keys.txt
bach build --key-file keys.txt
```

Every key in the file opens the same setup file (up to 1000 keys). Keep track of which key you gave to whom.

You can use your own keys: 8 to 128 characters, letters, digits and `- _ . ~ + / = :`. Random keys from `bach key` are much harder to guess.

## What users see

After requirements and before the license, a page asks for the key. They can type or paste it. A wrong key shows **That key doesn't fit** and nothing on the computer changes.

Silent installs take the key with `--key-file <file>` or the `BACH_ACCESS_KEY` environment variable, never as a plain argument, because other programs can read arguments:

```powershell theme={"theme":{"light":"github-light","dark":"github-dark"}}
Start-Process ".\Hello-Setup-1.4.0.exe" -ArgumentList '--silent', '--key-file', 'key.txt' -Wait -PassThru
```

Without a key the exit code is 2; with a wrong key, 1.

## Private updates

With `[updates]`, the key is kept on the user's computer, protected so only that Windows account can read it, and sent with update requests:

```toml bach.toml theme={"theme":{"light":"github-light","dark":"github-dark"}}
[access]
get_key_url = "https://example.com/buy"

[updates]
feed = "https://downloads.example.com/hello/latest.json"
download_url = "https://downloads.example.com/hello/{file}"
```

Your server receives `Authorization: Bearer <key>` and can answer `401` or `403` to refuse. The key only goes to the host of `feed`. See [Where to host updates](/docs/guides/update-hosting.md#private-updates).

## Taking a key back

Remove the line from `keys.txt` and build again. Copies of the old setup file still open with the old key, but your server can refuse its update requests.

## What this protects, and what it doesn't

It protects the setup file and the download: without a key, nobody can unpack your files. It doesn't protect an installed app. After installing, the files are ordinary files on the user's computer, and file names and sizes are visible even without a key. If you need licensing, check the license inside your app.

Access keys can't be combined with [downloaded components](/docs/guides/choices-and-components.md#download-a-component-only-when-its-wanted) (while files are encrypted), portable ZIPs or MSI packages.

For every setting, see [`[access]`](/docs/reference/config/access).


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