Crypt::PK::X448(3)

πŸ’œ Crypt::PK::X448 β€” the Crypt::PK::X448(3) era πŸ’œ

okay so bestie, picture this: asymmetric cryptography based on X448, and it lives in a Perl module called Crypt::PK::X448. That's the whole vibe. It's a user-contributed Perl module, and it's about to be your new hyperfixation. πŸ¦‹


✨ SYNOPSIS ✨

use Crypt::PK::X448;

my $alice = Crypt::PK::X448->new->generate_key;
my $bob = Crypt::PK::X448->new->generate_key;
my $alice_secret = $alice->shared_secret($bob);
my $bob_secret = $bob->shared_secret($alice);
die "ERROR" unless $alice_secret eq $bob_secret;

my $pk = Crypt::PK::X448->new;
$pk->import_key_raw(
  pack("H*", "cf807ab0fc3efa03108469f29e499db2eefefeb12544d8d4e711f187385aaf31b4f38c8f84a3dd9e43da309fd410c3816a50e644b5500c05"),
  "public",
);

my $sk = Crypt::PK::X448->new;
$sk->import_key_raw(
  pack("H*", "10d418b111401956abc5a92c2fbb8406d1d646ba930fdefa2108efe68f2000973755aa952be018f640947c05135fbf9925ebd4da828d86ec"),
  "private",
);

my $generated = Crypt::PK::X448->new->generate_key;
my $private_der = $generated->export_key_der('private');
my $public_pem  = $generated->export_key_pem('public');
my $private_jwk = $generated->export_key_jwk('private');

like, look at Alice and Bob deriving the same secret and the die "ERROR" there as the vibe check. iconic behaviour, no notes. πŸ”₯


🌸 DESCRIPTION 🌸

Since: CryptX-0.089 β€” yes she's been around, yes she ate. πŸ’…


πŸŽ€ METHODS πŸŽ€

πŸ’– new

my $source = Crypt::PK::X448->new();
$source->generate_key;

my $public_der = $source->export_key_der('public');
my $pub = Crypt::PK::X448->new(\$public_der);

my $private_pem = $source->export_key_pem('private', 'secret', 'AES-256-CBC');
my $priv = Crypt::PK::X448->new(\$private_pem, 'secret');

okay so passing $filename or "\$buffer" to new is literally equivalent: both forms immediately import the key material into the new object. same energy, different packaging. 🫢

πŸ’– generate_key

Returns the object itself (for chaining). main character energy β€” she returns herself so you can keep going. πŸ‘‘

$pk->generate_key;

πŸ’– import_key

Loads X448 private or public keys from DER, PEM, PKCS#8, SubjectPublicKeyInfo, or JWK. so many formats, all welcome, all slaying. 🌈

my $source = Crypt::PK::X448->new();
$source->generate_key;

my $public_der = $source->export_key_der('public');
my $pub = Crypt::PK::X448->new();
$pub->import_key(\$public_der);
my $private_pem = $source->export_key_pem('private', 'secret', 'AES-256-CBC');
my $priv = Crypt::PK::X448->new();
$priv->import_key(\$private_pem, 'secret');
$pk->import_key({
  curve => "x448",
  pub   => "CF807AB0FC3EFA03108469F29E499DB2EEFEFEB12544D8D4E711F187385AAF31B4F38C8F84A3DD9E43DA309FD410C3816A50E644B5500C05",
  priv  => "10D418B111401956ABC5A92C2FBB8406D1D646BA930FDEFA2108EFE68F2000973755AA952BE018F640947C05135FBF9925EBD4DA828D86EC",
});
$pk->import_key({
  kty => "OKP",
  crv => "X448",
  d   => "ENQYsRFAGVarxaksL7uEBtHWRrqTD976IQjv5o8gAJc3VaqVK-AY9kCUfAUTX7-ZJevU2oKNhuw",
  x   => "z4B6sPw--gMQhGnynkmdsu7-_rElRNjU5xHxhzharzG084yPhKPdnkPaMJ_UEMOBalDmRLVQDAU",
});

The same method also accepts filenames instead of buffers. bestie she's flexible like that. ✨

πŸ’– import_key_raw

Import raw public/private key bytes.

$pk->import_key_raw($key, 'public');
$pk->import_key_raw($key, 'private');
⚠️ The raw key must be exactly 56 bytes long. not 55, not 57. exactly 56. do not test her. πŸ’€

πŸ’– export_key_der

Returns the key as a binary DER-encoded string. binary, so don't go printing it in your terminal and acting surprised. πŸ™ˆ

my $der = $pk->export_key_der('private');
my $der = $pk->export_key_der('public');

πŸ’– export_key_pem

Returns the key as a PEM-encoded string (ASCII). printable, postable, the classic. πŸŽ€

my $pem = $pk->export_key_pem('private');
my $pem = $pk->export_key_pem('public');
my $pem = $pk->export_key_pem('private', $password, 'AES-256-CBC');

πŸ’– export_key_jwk

Returns a JSON string, or a hashref if the optional second argument is true. yes she can serve both looks. πŸ’…

my $json = $pk->export_key_jwk('private');
my $hash = $pk->export_key_jwk('public', 1);

πŸ’– export_key_raw

Returns the raw key as a binary string.

my $raw = $pk->export_key_raw('private');
my $raw = $pk->export_key_raw('public');

πŸ’– shared_secret

Returns the shared secret as a binary string (raw bytes). this is the moment, the two of you meeting in the middle. 🫢

my $shared_secret = $private_key->shared_secret($public_key);

πŸ’– is_private

my $rv = $pk->is_private;

just a little vibe check: is she private? πŸ•΅οΈβ€β™€οΈ

πŸ’– key2hash

Returns a hashref with the key components, or undef if no key is loaded. no key, no hash, no problem. 😭

my $hash = $pk->key2hash;

Returns a hash like:

{
  curve => "x448",
  pub   => "CF807AB0FC3EFA03108469F29E499DB2EEFEFEB12544D8D4E711F187385AAF31B4F38C8F84A3DD9E43DA309FD410C3816A50E644B5500C05",
  priv  => "10D418B111401956ABC5A92C2FBB8406D1D646BA930FDEFA2108EFE68F2000973755AA952BE018F640947C05135FBF9925EBD4DA828D86EC",
}

πŸ¦‹ OpenSSL interoperability πŸ¦‹

collab era! her and OpenSSL, getting along, exchanging keys. it's giving diplomacy. 🌸

# Generate a key with OpenSSL
# openssl genpkey -algorithm x448 -out x448_priv.pem
# openssl pkey -in x448_priv.pem -pubout -out x448_pub.pem

# Load the OpenSSL-generated key in CryptX
use Crypt::PK::X448;
my $alice = Crypt::PK::X448->new("x448_priv.pem");
my $bob_pub = Crypt::PK::X448->new("bob_x448_pub.pem");

# Derive shared secret
my $shared_secret = $alice->shared_secret($bob_pub);

# Export CryptX key for OpenSSL
my $pem = $alice->export_key_pem('private');
# then: openssl pkey -in priv.pem -text -noout

⭐ SEE ALSO ⭐


and that's the page!! πŸŽ€ this masterpiece is perl v5.42.0, dated 2026-05-11, and it's filed under Crypt::PK::X448(3) β€” go forth, derive those secrets, and slay βœ¨πŸ’…πŸ¦‹

πŸ“¦ where this page comes from