| Title: | File Encryption with the 'age' Format |
|---|---|
| Description: | An idiomatic R interface to the 'age' file encryption format (<https://age-encryption.org/v1>), backed by a vendored copy of the 'agec' C implementation (<https://git.sr.ht/~min/agec>). Encrypt and decrypt raw vectors, files, and strings for one or more X25519 recipients or with a passphrase, with optional ASCII armor. Cryptography is vendored and randomness is drawn from the operating system, so the package has no external library dependencies. |
| Authors: | Pedro Baltazar [aut, cre, cph], agec authors [ctb, cph] (Authors of the vendored 'agec' C implementation, https://git.sr.ht/~min/agec) |
| Maintainer: | Pedro Baltazar <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-10-01 00:05:39 UTC |
| Source: | https://github.com/pedrobtz/agecrypt |
File-to-file encryption. Large files are streamed in constant memory in C (they are not loaded into an R vector).
age_encrypt_file( input, output = NULL, recipients, armor = FALSE, overwrite = FALSE ) age_decrypt_file(input, output = NULL, identities, overwrite = FALSE)age_encrypt_file( input, output = NULL, recipients, armor = FALSE, overwrite = FALSE ) age_decrypt_file(input, output = NULL, identities, overwrite = FALSE)
input |
Path to the source file. |
output |
Destination path. If |
recipients |
Character vector of |
armor |
If |
overwrite |
If |
identities |
An |
The output path, invisibly.
id <- age_keygen() rec <- age_pubkey(id) f <- tempfile(fileext = ".txt") writeLines("hello", f) enc <- age_encrypt_file(f, recipients = rec) dec <- age_decrypt_file(enc, output = tempfile(), identities = id) readLines(dec)id <- age_keygen() rec <- age_pubkey(id) f <- tempfile(fileext = ".txt") writeLines("hello", f) enc <- age_encrypt_file(f, recipients = rec) dec <- age_decrypt_file(enc, output = tempfile(), identities = id) readLines(dec)
Parse or load age identities
age_identity(x)age_identity(x)
x |
A character vector of inline |
An age_identity object.
id <- age_keygen() # round-trip through a key file f <- tempfile() age_keygen(f) id2 <- age_identity(f)id <- age_keygen() # round-trip through a key file f <- tempfile() age_keygen(f) id2 <- age_identity(f)
Zeroes and frees the secret bytes immediately rather than waiting for garbage collection. The identity becomes unusable afterwards.
age_identity_free(identity)age_identity_free(identity)
identity |
An |
invisible(NULL).
id <- age_keygen() age_identity_free(id)id <- age_keygen() age_identity_free(id)
Creates a fresh X25519 identity (key pair). The secret key is generated in C
and never returned to R; to persist it, pass path so it is written
directly to a key file in the standard age format.
age_keygen(path = NULL, overwrite = FALSE)age_keygen(path = NULL, overwrite = FALSE)
path |
Optional file path. If given, the identity is written as a key
file ( |
overwrite |
If |
An age_identity object. Its print method shows only the public
key; the secret is never printed.
id <- age_keygen() id age_pubkey(id)id <- age_keygen() id age_pubkey(id)
Passphrase-based (scrypt) encryption, a separate mode from the
recipient-based age_encrypt_raw() family. A file encrypted this way is
decrypted with the matching age_decrypt_*_passphrase() function and the
same passphrase — no key pair is involved.
age_encrypt_raw_passphrase(x, passphrase = NULL, armor = FALSE, log_n = 18) age_decrypt_raw_passphrase(x, passphrase = NULL) age_encrypt_file_passphrase( input, output = NULL, passphrase = NULL, armor = FALSE, overwrite = FALSE, log_n = 18 ) age_decrypt_file_passphrase( input, output = NULL, passphrase = NULL, overwrite = FALSE )age_encrypt_raw_passphrase(x, passphrase = NULL, armor = FALSE, log_n = 18) age_decrypt_raw_passphrase(x, passphrase = NULL) age_encrypt_file_passphrase( input, output = NULL, passphrase = NULL, armor = FALSE, overwrite = FALSE, log_n = 18 ) age_decrypt_file_passphrase( input, output = NULL, passphrase = NULL, overwrite = FALSE )
x |
For |
passphrase |
A length-1 character string. If |
armor |
If |
log_n |
scrypt work factor, as the base-2 logarithm of the parameter N. Higher is slower and more brute-force resistant. Defaults to 18; values above 22 are rejected (also on decrypt) to bound work. |
input, output
|
File paths. |
overwrite |
If |
The raw functions return a raw vector; the file functions return the output path invisibly.
ct <- age_encrypt_raw_passphrase( charToRaw("secret"), passphrase = "hunter2", log_n = 8 ) rawToChar(age_decrypt_raw_passphrase(ct, passphrase = "hunter2"))ct <- age_encrypt_raw_passphrase( charToRaw("secret"), passphrase = "hunter2", log_n = 8 ) rawToChar(age_decrypt_raw_passphrase(ct, passphrase = "hunter2"))
Derive public recipient strings from identities
age_pubkey(identities)age_pubkey(identities)
identities |
An |
A character vector of "age1..." recipient strings, one per
identity.
id <- age_keygen() age_pubkey(id)id <- age_keygen() age_pubkey(id)
The core buffer transforms: no file I/O, nothing written to disk. All other
verbs (_file, _text) build on these.
age_encrypt_raw(x, recipients, armor = FALSE) age_decrypt_raw(x, identities)age_encrypt_raw(x, recipients, armor = FALSE) age_decrypt_raw(x, identities)
x |
For |
recipients |
Character vector of |
armor |
If |
identities |
An |
A raw vector: ciphertext for age_encrypt_raw(), plaintext for
age_decrypt_raw().
id <- age_keygen() rec <- age_pubkey(id) ct <- age_encrypt_raw(charToRaw("hello"), recipients = rec) rawToChar(age_decrypt_raw(ct, identities = id))id <- age_keygen() rec <- age_pubkey(id) ct <- age_encrypt_raw(charToRaw("hello"), recipients = rec) rawToChar(age_decrypt_raw(ct, identities = id))
Convenience wrappers over age_encrypt_raw() / age_decrypt_raw() for one
string, ASCII-armored by default so the result is copy-pasteable. Encoding
is forced to UTF-8 on the way in and marked on the way out.
age_encrypt_text(x, recipients, armor = TRUE) age_decrypt_text(x, identities)age_encrypt_text(x, recipients, armor = TRUE) age_decrypt_text(x, identities)
x |
For |
recipients |
Character vector of |
armor |
Must be |
identities |
An |
age_encrypt_text() returns a length-1 character string;
age_decrypt_text() returns a length-1 UTF-8 string. age_decrypt_text()
signals age_error_decrypt if the plaintext is not valid UTF-8 text (for
binary payloads, use age_decrypt_raw()).
id <- age_keygen() rec <- age_pubkey(id) ct <- age_encrypt_text("db_password_123", recipients = rec) age_decrypt_text(ct, identities = id)id <- age_keygen() rec <- age_pubkey(id) ct <- age_encrypt_text("db_password_123", recipients = rec) age_decrypt_text(ct, identities = id)