Skip to main content
coreydaley.dev
Docs menu

Encrypt files with Apple Encrypted Archive (.aea) on a Mac

An Apple Encrypted Archive (.aea) is an Apple Archive with encryption. The file names are encrypted too: nothing in the file says what’s inside until it’s opened. macOS can make one four ways:

ModeYou open it withGood for
PasswordThe passwordYour own backups, or sharing with someone you can give a password to
Key fileA random 256-bit key in a fileScripts and automated backups
Public keyThe recipient’s private keySending to someone without sharing a secret
Public key + signatureThe recipient’s private key and the sender’s public keyProving who made it

Archive Utility does the password mode. Terminal’s aa command does all four.

With a password, in Archive Utility

  1. In Archive Utility ▸ Settings, set Use archive format to Apple Encrypted Archive.
  2. Choose File ▸ Create Archive…, select the folder and click Archive.
  3. Archive Utility fills in a random password for you: six groups of five digits. You can type your own instead.
Archive Utility password sheet with a generated password, a Store Password in Keychain checkbox, and Cancel and Encrypt buttons

Store Password in Keychain is ticked by default. Leave it ticked and the Mac remembers the password; untick it and the only copy is the one you write down. Either way, copy the password somewhere safe before you click Encrypt: there’s no way to recover it.

To open the .aea, double-click it. Archive Utility asks for the password, again offering to store it in the Keychain.

Archive Utility asking for the password for Project.aea, with Store Password in Keychain ticked

With a password, in Terminal

aa can make the password for you and save it to a file. The umask 077 makes that file readable only by you:

(umask 077; aa archive -D ~/Projects/Site -o ~/Desktop/Site.aea -password-gen -password ~/Desktop/Site.password)
mkdir -p ~/Desktop/Restored
aa extract -i ~/Desktop/Site.aea -d ~/Desktop/Restored -password ~/Desktop/Site.password

Keep the password file somewhere other than next to the archive. To type a password of your own without it landing in your shell history:

read -s "P?Password: "
aa archive -D ~/Projects/Site -o ~/Desktop/Site.aea -password-value "$P"

The password is still visible to other processes on the Mac while aa runs; for anything sensitive, use a password file.

That read -s "P?…" form is for zsh, the Mac’s default shell.

The password needs at least 20 bytes. For plain English letters, digits and punctuation, that’s 20 characters. On macOS 27.2, 19 failed with “Password is too short”, whatever they were, and 20 worked; the most it takes is 256 bytes. Apple doesn’t document these limits. macOS 14.8.9, 15.8.2 and 26.6.2 gave the same results, and each opened a 20-character .aea made on 27.2. A passphrase of four or five random words gets there easily. Purrchiver asks for the same 20 to 256 when it makes an .aea, and opens one with any password aa accepts.

A failed command still leaves an empty .aea file behind, so delete it before trying again.

With a key file

A key file holds a random 256-bit key instead of a password. It’s the mode for scripts:

(umask 077; aa archive -D ~/Projects/Site -o ~/Desktop/Site.aea -key-gen -key ~/Desktop/Site.key)
mkdir -p ~/Desktop/Restored
aa extract -i ~/Desktop/Site.aea -d ~/Desktop/Restored -key ~/Desktop/Site.key

The key file is one line of text starting hex:. Archive Utility can’t open a key-encrypted .aea: double-clicking one gave “Error 79 - Inappropriate file type or format”.

Archive Utility alert: Unable to expand Project.aea, Error 79 - Inappropriate file type or format

With a public key

With a public key, you encrypt to someone, and only their private key opens it. Nobody has to share a password or key first.

macOS has no command that writes keys in the form aa reads, but a few lines of Swift do. They use Apple’s CryptoKit and need the Command Line Tools (xcode-select --install). Save this as aea-keys.swift:

import CryptoKit
import Foundation

func save(_ data: Data, _ name: String) {
    FileManager.default.createFile(atPath: name,
        contents: Data(("base64:" + data.base64EncodedString()).utf8),
        attributes: [.posixPermissions: 0o600])
}

let recipient = P256.KeyAgreement.PrivateKey()
save(recipient.x963Representation, "recipient.priv")
save(recipient.publicKey.x963Representation, "recipient.pub")

let sender = P256.Signing.PrivateKey()
save(sender.x963Representation, "sender.priv")
save(sender.publicKey.x963Representation, "sender.pub")

Run it in an empty folder with swift aea-keys.swift. It writes four files into that folder; run the commands below from the same folder, or give the full path to each key. The base64: at the start of each matters: aa rejected the same keys saved as raw bytes (“Error parsing public key file”).

To encrypt to the recipient, and to open it as the recipient:

aa archive -D ~/Projects/Site -o ~/Desktop/Site.aea -recipient-pub recipient.pub
mkdir -p ~/Desktop/Restored
aa extract -i ~/Desktop/Site.aea -d ~/Desktop/Restored -recipient-priv recipient.priv

To sign it as well, add the sender’s private key when you make it. The recipient then needs the sender’s public key to open it, and it won’t open with any other:

aa archive -D ~/Projects/Site -o ~/Desktop/Site.aea -recipient-pub recipient.pub -sign-priv sender.priv
aa extract -i ~/Desktop/Site.aea -d ~/Desktop/Restored -recipient-priv recipient.priv -sign-pub sender.pub

When it won’t open

Every wrong credential I tried failed with “unlock container” and nothing extracted: a wrong password, a wrong key, the wrong private key, a missing signer key, and the wrong signer key. For a wrong password, key or private key, that’s all it says; the signer errors add a line or two more.

aa handles the encryption itself. The separate aea command encrypts any single file, and has a few more options, such as -profile, sign and id; run aea with no arguments for the list.