Generate a new age identity (key pair)

Description

Create a new age encryption key pair and save it to a file. The key pair consists of a public key (for encryption) and a private key (for decryption). If the specified key file already exists, the function will error to prevent overwriting.

Usage

key_generate(keyfile = NULL)

Arguments

keyfile Character string, path where the private key will be saved. The file will contain both public and private key information.

Value

A lockbox_key object which is a character string containing the public key (age recipient identifier) with a created attribute containing the timestamp of key creation.

Security Warning

The private key file is created using the system’s default file permissions, which may be readable by other users (typically 0644 on Unix systems). After generating a key, you should immediately set restrictive permissions:

# On Unix/Linux/macOS: key <- key_generate(“my_identity.key”) Sys.chmod(“my_identity.key”, “0600”) # Owner read/write only

On Windows, store keys in a secure location like %USERPROFILE%\.config\lockbox\ and rely on NTFS ACLs for protection.

Examples

library("lockbox")

# Generate and save new key to file
key <- key_generate("my_identity.key")
print(key) # prints the public key
print(attr(key, "created")) # prints creation time

# IMPORTANT: Secure the key file permissions
Sys.chmod("my_identity.key", "0600")