X25519
Decrypt age files with X25519 identities.
from oxcrypto.age.x25519 import AGE
identity = AGE.X25519.load_identity("AGE-SECRET-KEY-1...")
print(AGE.X25519.recipient(identity.public_key())) # age1...
plaintext = AGE.X25519.decrypt(open("file.age", "rb").read(), [identity])load_identity reads an AGE-SECRET-KEY-1... Bech32 string into an
X25519PrivateKey, and load_recipient reads an age1... string into an
X25519PublicKey; both accept all-uppercase or all-lowercase strings and
raise ValueError for any other prefix, length or checksum. recipient
returns the lowercase age1... string for a public key, which other age
implementations can encrypt to.
decrypt(data, identities) takes the whole file, binary or ASCII-armored,
and a non-empty list of private keys, tried in order. It returns the
plaintext only once every STREAM chunk has authenticated, and never returns a
partial payload. It raises:
ValueErrorfor malformed armor, a malformed or unsupported header, an empty identity list, or a file encrypted to an scrypt passphrase;oxcrypto.InvalidTagwhen no identity unwraps the file key, the header MAC does not match, or the payload does not authenticate, including truncation and trailing data.
Files with an scrypt recipient are rejected before any key derivation, so
work factors read from the header never run. The X25519 stanza is unwrapped
with the oxcrypto key through the age::Identity trait, following the
specification's rules for canonical base64 shares, 32-byte bodies and
all-zero shared secrets.
Upstream
| Crate | Standard | Maturity |
|---|---|---|
age 0.11.5, age-core 0.11.0 | age-encryption.org/v1 (C2SP) | Stable format; maintained 0.11 release line |
Both crates build with Rust 1.88, the oxcrypto MSRV. Tests use the C2SP CCTV
age test kit files whose identities are all X25519. As in the age crate's
own test kit, age 0.11.5 rejects armored files with leading whitespace
(armor_whitespace_outside) and accepts stanzas that lack their final short
body line (stanza_missing_body, stanza_missing_final_line).
Zeroization
Note
The X25519 shared secret, the HKDF wrapping key, the unwrapped file key,
the header MAC key, the payload key, the ChaCha20-Poly1305 key and
keystream state, each decrypted chunk and the output buffer are written to
be wiped when dropped; oxcrypto has not verified the upstream code
independently. Not covered: identity strings, ciphertext and plaintext
passed in or returned as Python str or bytes; stack copies made by
hkdf 0.12, hmac 0.12, sha2 0.10 and poly1305 0.8, which have no
zeroize support; and the old allocation if the allocator moves a decrypted
chunk when age shrinks it into a boxed slice.