The age v1 file format with X25519 keys, in pure Elixir.
It uses only OTP :crypto. Files work with the age and rage tools in both
directions, binary or ASCII-armored.
Two key types work: X25519 (age1...) and the hybrid post-quantum
ML-KEM-768 + X25519 type (age1pq1...). The post-quantum type needs OpenSSL
3.5 or later in OTP. Without it, the operations that need ML-KEM return
{:error, :unsupported}.
encrypt/3 also accepts YubiKey recipients (age1yubikey1...) from
age-plugin-yubikey. Only the
YubiKey can decrypt them, with the age CLI and the plugin.
Not supported: passphrases (scrypt), SSH keys, other plugins. All data stays in memory.
Example
%{identity: identity, recipient: recipient} = AgeEx.generate_identity()
{:ok, ciphertext} = AgeEx.encrypt("secret", recipient)
{:ok, "secret"} = AgeEx.decrypt(ciphertext, identity)
Summary
Types
Why an operation failed. The decrypt reasons match the classes of the C2SP age test vectors.
A private key: AGE-SECRET-KEY-1... or AGE-SECRET-KEY-PQ-1....
A public key: age1..., age1pq1... or age1yubikey1....
Functions
Decrypts an age file with one identity or a list of them.
Encrypts plaintext to one recipient or a list of them.
Generates a new key pair.
Reads the identities from the text of a key file, as age-keygen writes it.
Returns the recipient (public key) of an identity.
Types
@type error() ::
:invalid_identity
| :invalid_recipient
| :no_recipients
| :incompatible_recipients
| :unsupported
| :armor_failure
| :header_failure
| :no_match
| :hmac_failure
| :payload_failure
Why an operation failed. The decrypt reasons match the classes of the C2SP age test vectors.
@type identity() :: String.t()
A private key: AGE-SECRET-KEY-1... or AGE-SECRET-KEY-PQ-1....
@type recipient() :: String.t()
A public key: age1..., age1pq1... or age1yubikey1....
Functions
Decrypts an age file with one identity or a list of them.
Accepts binary and ASCII-armored files. Nothing is returned unless the whole file decrypts and authenticates.
@spec encrypt(iodata(), recipient() | [recipient()], keyword()) :: {:ok, binary()} | {:error, error()}
Encrypts plaintext to one recipient or a list of them.
Post-quantum recipients cannot be mixed with X25519 or YubiKey recipients,
because the file would then have no protection against quantum computers.
The age CLI refuses this too.
Options
:armor- whentrue, returns ASCII-armored text. Defaults tofalse.
Generates a new key pair.
Options
:post_quantum- whentrue, makes a hybrid ML-KEM-768 + X25519 key, asage-keygen -pqdoes. Defaults tofalse.
Reads the identities from the text of a key file, as age-keygen writes it.
Empty lines and lines that start with # are skipped. Every other line must
be an identity: X25519 (age-keygen) or post-quantum (age-keygen -pq).
Returns the recipient (public key) of an identity.