Skip to main content

build_keypair

Function build_keypair 

Source
pub fn build_keypair() -> Result<KeyPair>
Expand description

Generates a new age X25519 key pair.

Creates a fresh Identity using the age library, extracts the public and secret components, validates both, and returns them as a KeyPair.

§Performance

This operation involves cryptographic key generation and is relatively expensive. The result is marked #[must_use] to discourage discarding generated keys accidentally. Consider caching the KeyPair when possible.

§Errors

Returns Error::Generation if the underlying age identity generation fails.

§Examples

use age_setup::build_keypair;

let kp = build_keypair()?;
println!("Public key: {}", kp.public);
// Secret key is not displayed: the Debug impl redacts it.
println!("KeyPair: {:?}", kp);

§See Also