NAME

Crypt::Age::Keys - Key generation and Bech32 encoding for age encryption

VERSION

version 0.001

SYNOPSIS

use Crypt::Age::Keys;

# Generate keypair
my ($public, $secret) = Crypt::Age::Keys->generate_keypair();

# Encode/decode public keys
my $encoded_public = Crypt::Age::Keys->encode_public_key($public_bytes);
my $public_bytes = Crypt::Age::Keys->decode_public_key('age1...');

# Encode/decode secret keys
my $encoded_secret = Crypt::Age::Keys->encode_secret_key($secret_bytes);
my $secret_bytes = Crypt::Age::Keys->decode_secret_key('AGE-SECRET-KEY-1...');

# Derive public key from secret key
my $public = Crypt::Age::Keys->public_key_from_secret($secret);

DESCRIPTION

This module provides key generation and Bech32 encoding/decoding for age encryption.

age uses X25519 (Curve25519 Diffie-Hellman) for key agreement. Keys are encoded using Bech32, the same encoding used for Bitcoin SegWit addresses (BIP-173).

Public keys use the human-readable part age and are lowercase. Secret keys use the human-readable part age-secret-key- and are uppercase.

generate_keypair

my ($public_key, $secret_key) = Crypt::Age::Keys->generate_keypair();

Generates a new X25519 keypair.

Returns a list of two Bech32-encoded strings:

  • $public_key - Starts with age1, lowercase

  • $secret_key - Starts with AGE-SECRET-KEY-1, uppercase

encode_public_key

my $encoded = Crypt::Age::Keys->encode_public_key($public_bytes);

Encodes a 32-byte X25519 public key as a Bech32 string with HRP age.

Returns a lowercase string starting with age1.

decode_public_key

my $public_bytes = Crypt::Age::Keys->decode_public_key('age1...');

Decodes a Bech32-encoded age public key to raw bytes.

Dies if the HRP is not age or if the decoded data is not 32 bytes.

encode_secret_key

my $encoded = Crypt::Age::Keys->encode_secret_key($secret_bytes);

Encodes a 32-byte X25519 secret key as a Bech32 string with HRP age-secret-key-.

Returns an uppercase string starting with AGE-SECRET-KEY-1.

decode_secret_key

my $secret_bytes = Crypt::Age::Keys->decode_secret_key('AGE-SECRET-KEY-1...');

Decodes a Bech32-encoded age secret key to raw bytes.

Dies if the HRP is not age-secret-key- or if the decoded data is not 32 bytes.

public_key_from_secret

my $public_key = Crypt::Age::Keys->public_key_from_secret($secret_key);

Derives the public key from a secret key.

Takes a Bech32-encoded secret key and returns the corresponding Bech32-encoded public key. This is useful for when you have a secret key and need to know what public key it corresponds to.

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/p5-crypt-age/issues.

IRC

You can reach Getty on irc.perl.org for questions and support.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.