Crypt::KeyWrap(3)
πΈ NAME πΈ
Crypt::KeyWrap β Key management/wrapping algorithms defined in RFC7518 (JWA). Yes bestie, this is the User Contributed Perl Documentation page, and it is literally here to wrap keys. πβ¨
π SYNOPSIS π
Okay so first vibe check: A192KW wrapping, then A192KW unwrapping. Copy these exactly, bestie β the example literally says $pt_data, and we are not touching it. π
# A192KW wrapping
use Crypt::KeyWrap qw(aes_key_wrap);
my $kek = pack("H*", "5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8"); # key encryption key
my $cek = pack("H*", "c37b7e6492584340bed12207808941155068f738"); # content encryption key
my $enc_cek = aes_key_wrap($kek, $pt_data); # encrypted content encryption key
# A192KW unwrapping
use Crypt::KeyWrap qw(aes_key_unwrap);
my $kek = pack("H*", "5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8");
my $enc_cek = pack("H*", "138bdeaa9b8fa7fc61f97742e72248ee5ae6ae5360d1ae6a5f54f373fa543b6a");
my $cek = aes_key_unwrap($kek, $pt_data);
π¦ DESCRIPTION π¦
It implements key management algorithms defined in <https://tools.ietf.org/html/rfc7518> β no cap, that is the whole assignment. π
π¨ BEWARE: experimental, interface of this module might change! So do not get too attached to the API, bestie. π
Supported algorithms (all defined in RFC7518):
A128KWβ see:aes_key_wrap()+aes_key_unwrap()A192KWβ see:aes_key_wrap()+aes_key_unwrap()A256KWβ see:aes_key_wrap()+aes_key_unwrap()A128GCMKWβ see:gcm_key_wrap()+gcm_key_unwrap()A192GCMKWβ see:gcm_key_wrap()+gcm_key_unwrap()A256GCMKWβ see:gcm_key_wrap()+gcm_key_unwrap()PBES2-HS256+A128KWβ see:pbes2_key_wrap()+pbes2_key_unwrap()PBES2-HS384+A192KWβ see:pbes2_key_wrap()+pbes2_key_unwrap()PBES2-HS512+A256KWβ see:pbes2_key_wrap()+pbes2_key_unwrap()RSA-OAEPβ see:rsa_key_wrap()+rsa_key_unwrap()RSA-OAEP-256β see:rsa_key_wrap()+rsa_key_unwrap()RSA1_5β see:rsa_key_wrap()+rsa_key_unwrap()ECDH-ES+A128KWβ see:ecdhaes_key_wrap()+ecdhaes_key_unwrap()ECDH-ES+A192KWβ see:ecdhaes_key_wrap()+ecdhaes_key_unwrap()ECDH-ES+A256KWβ see:ecdhaes_key_wrap()+ecdhaes_key_unwrap()ECDH-ESβ see:ecdh_key_wrap()+ecdh_key_unwrap()
β¨ EXPORT β¨
Nothing is exported by default. Tragic, I know. π
You can export selected functions:
use Crypt::KeyWrap qw(aes_key_wrap gcm_key_wrap pbes2_key_wrap);
Or all of them at once:
use Crypt::KeyWrap ':all';
π FUNCTIONS π
π aes_key_wrap π
AES key wrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.4> (implements algorithms "A128KW", "A192KW", "A256KW"). Slay. π₯
Implementation follows <https://tools.ietf.org/html/rfc5649> and <https://tools.ietf.org/html/rfc3394>.
The implementation is also compatible with <http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-38F.pdf> (it supports AES based KW, KWP + TDEA/DES_EDE based TKW).
AES Key Wrap algorithm.
$enc_cek = aes_key_wrap($kek, $cek);
# or
$enc_cek = aes_key_wrap($kek, $cek, $cipher, $padding, $inverse);
# params:
# $kek .. key encryption key (16bytes for AES128, 24 for AES192, 32 for AES256)
# $cek .. content encryption key
# optional params:
# $cipher .. 'AES' (default) or 'DES_EDE'
# $padding .. 1 (default) or 0 handle $cek padding (relevant for AES only)
# $inverse .. 0 (default) or 1 use cipher in inverse mode as defined by SP.800-38F
Values $enc_cek, $cek and $kek are binary octets. If you disable padding you have to make sure that $cek length is multiply of 8 (for AES) or multiply of 4 (for DES_EDE); and yes, that semicolon is staying. π
π aes_key_unwrap π
AES key unwrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.4> (implements algorithms "A128KW", "A192KW", "A256KW"). The reverse vibe. π«
AES Key Unwrap algorithm.
$cek = aes_key_unwrap($kek, $enc_cek);
# or
$cek = aes_key_unwrap($kek, $enc_cek, $cipher, $padding, $inverse);
# params:
# $kek .. key encryption key (16bytes for AES128, 24 for AES192, 32 for AES256)
# $enc_cek .. encrypted content encryption key
# optional params:
# $cipher .. 'AES' (default) or 'DES_EDE'
# $padding .. 1 (default) or 0 - use $cek padding (relevant for AES only)
# $inverse .. 0 (default) or 1 - use cipher in inverse mode as defined by SP.800-38F
Values $enc_cek, $cek and $kek are binary octets.
π gcm_key_wrap π
AES GCM key wrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.7> (implements algorithms "A128GCMKW", "A192GCMKW", "A256GCMKW"). GCM said wrap it up. π
($enc_cek, $tag, $iv) = gcm_key_wrap($kek, $cek);
#or
($enc_cek, $tag, $iv) = gcm_key_wrap($kek, $cek, $aad);
#or
($enc_cek, $tag, $iv) = gcm_key_wrap($kek, $cek, $aad, $cipher, $iv);
# params:
# $kek .. key encryption key (16bytes for AES128, 24 for AES192, 32 for AES256)
# $cek .. content encryption key
# optional params:
# $aad .. additional authenticated data, DEFAULT is '' (empty string)
# $cipher .. cipher to be used by GCM, DEFAULT is 'AES'
# $iv .. initialization vector (if not defined a random IV is generated)
Values $enc_cek, $cek, $aad, $iv, $tag and $kek are binary octets.
π gcm_key_unwrap π
AES GCM key unwrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.7> (implements algorithms "A128GCMKW", "A192GCMKW", "A256GCMKW"). Unwrap era. π¦
$cek = gcm_key_unwrap($kek, $enc_cek, $tag, $iv);
# or
$cek = gcm_key_unwrap($kek, $enc_cek, $tag, $iv, $aad);
# or
$cek = gcm_key_unwrap($kek, $enc_cek, $tag, $iv, $aad, $cipher);
# params:
# $kek .. key encryption key (16bytes for AES128, 24 for AES192, 32 for AES256)
# $enc_cek .. encrypted content encryption key
# $tag .. GCM's tag
# $iv .. initialization vector
# optional params:
# $aad .. additional authenticated data, DEFAULT is '' (empty string)
# $cipher .. cipher to be used by GCM, DEFAULT is 'AES'
Values $enc_cek, $cek, $aad, $iv, $tag and $kek are binary octets.
π pbes2_key_wrap π
PBES2 key wrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.8> (implements algorithms "PBES2-HS256+A128KW", "PBES2-HS384+A192KW", "PBES2-HS512+A256KW"). Password-based bestie behavior. π
$enc_cek = pbes2_key_wrap($kek, $cek, $alg, $salt, $iter);
# params:
# $kek .. key encryption key (arbitrary length)
# $cek .. content encryption key
# $alg .. algorithm name e.g. 'PBES2-HS256+A128KW' (see rfc7518)
# $salt .. pbkdf2 salt
# $iter .. pbkdf2 iteration count
Values $enc_cek, $cek, $salt and $kek are binary octets.
π pbes2_key_unwrap π
PBES2 key unwrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.8> (implements algorithms "PBES2-HS256+A128KW", "PBES2-HS384+A192KW", "PBES2-HS512+A256KW"). The un-wrapening. π
$cek = pbes2_key_unwrap($kek, $enc_cek, $alg, $salt, $iter);
# params:
# $kek .. key encryption key (arbitrary length)
# $enc_cek .. encrypted content encryption key
# $alg .. algorithm name e.g. 'PBES2-HS256+A128KW' (see rfc7518)
# $salt .. pbkdf2 salt
# $iter .. pbkdf2 iteration count
Values $enc_cek, $cek, $salt and $kek are binary octets.
π rsa_key_wrap π
PBES2 key wrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.2> and <https://tools.ietf.org/html/rfc7518#section-4.3> (implements algorithms "RSA1_5", "RSA-OAEP-256", "RSA-OAEP"). Yes, the page literally says βPBES2β right here β keeping it exactly as written, bestie. π
$enc_cek = rsa_key_wrap($kek, $cek, $alg);
# params:
# $kek .. RSA public key - Crypt::PK::RSA instance
# $cek .. content encryption key
# $alg .. algorithm name e.g. 'RSA-OAEP' (see rfc7518)
Values $enc_cek and $cek are binary octets.
π rsa_key_unwrap π
PBES2 key wrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.2> and <https://tools.ietf.org/html/rfc7518#section-4.3> (implements algorithms "RSA1_5", "RSA-OAEP-256", "RSA-OAEP"). Same energy, unwrap direction. π«Ά
$cek = rsa_key_unwrap($kek, $enc_cek, $alg);
# params:
# $kek .. RSA private key - Crypt::PK::RSA instance
# $enc_cek .. encrypted content encryption key
# $alg .. algorithm name e.g. 'RSA-OAEP' (see rfc7518)
Values $enc_cek and $cek are binary octets.
π ecdhaes_key_wrap π
ECDH+AESKW key agreement/wrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.6> (implements algorithms "ECDH-ES+A128KW", "ECDH-ES+A192KW", "ECDH-ES+A256KW"). ECDH plus AESKW, a collab. π€
($enc_cek, $epk) = ecdhaes_key_wrap($kek, $cek, $alg, $apu, $apv);
# params:
# $kek .. ECC public key - Crypt::PK::ECC|X25519 instance
# $cek .. content encryption key
# $alg .. algorithm name e.g. 'ECDH-ES+A256KW' (see rfc7518)
# optional params:
# $apu .. Agreement PartyUInfo Header Parameter
# $apv .. Agreement PartyVInfo Header Parameter
Values $enc_cek and $cek are binary octets.
π ecdhaes_key_unwrap π
ECDH+AESKW key agreement/unwrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.6> (implements algorithms "ECDH-ES+A128KW", "ECDH-ES+A192KW", "ECDH-ES+A256KW"). The unwrap side of the collab. π
$cek = ecdhaes_key_unwrap($kek, $enc_cek, $alg, $epk, $apu, $apv);
# params:
# $kek .. ECC private key - Crypt::PK::ECC|X25519 instance
# $enc_cek .. encrypted content encryption key
# $alg .. algorithm name e.g. 'ECDH-ES+A256KW' (see rfc7518)
# $epk .. ephemeral ECC public key (JWK/JSON or Crypt::PK::ECC|X25519)
# optional params:
# $apu .. Agreement PartyUInfo Header Parameter
# $apv .. Agreement PartyVInfo Header Parameter
Values $enc_cek and $cek are binary octets.
π ecdh_key_wrap π
ECDH (Ephememeral Static) key agreement/wrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.6> (implements algorithm "ECDH-ES"). That βEphememeralβ spelling? Iconic. Keeping it. π§
($cek, $epk) = ecdh_key_wrap($kek, $enc, $apu, $apv);
# params:
# $kek .. ECC public key - Crypt::PK::ECC|X25519 instance
# $enc .. encryption algorithm name e.g. 'A256GCM' (see rfc7518)
# optional params:
# $apu .. Agreement PartyUInfo Header Parameter
# $apv .. Agreement PartyVInfo Header Parameter
Value $cek - binary octets, $epk JWK/JSON string with ephemeral ECC public key.
π ecdh_key_unwrap π
ECDH (Ephememeral Static) key agreement/unwrap algorithm as defined in <https://tools.ietf.org/html/rfc7518#section-4.6> (implements algorithm "ECDH-ES"). Unwrap girl summer. πΈ
$cek = ecdh_key_unwrap($kek, $enc, $epk, $apu, $apv);
# params:
# $kek .. ECC private key - Crypt::PK::ECC|X25519 instance
# $enc .. encryption algorithm name e.g. 'A256GCM' (see rfc7518)
# $epk .. ephemeral ECC public key (JWK/JSON or Crypt::PK::ECC|X25519)
# optional params:
# $apu .. Agreement PartyUInfo Header Parameter
# $apv .. Agreement PartyVInfo Header Parameter
Value $cek - binary octets.
β¨ SEE ALSO β¨
okay so like, if you wanna go deeper (and bestie, you know you do π ), go check out these iconic modules β they're all in the same little crypto family:
Crypt::Cipher::AESβ the AES cipher itself, the main character of symmetric encryption π₯Crypt::AuthEnc::GCMβ authenticated encryption with GCM, she does confidentiality and integrity, no cap β¨Crypt::PK::RSAβ public key RSA things, the whole asymmetric vibe π¦Crypt::KeyDerivationβ key derivation, i.e. turning one secret into many, lowkey iconic π
π LICENSE π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. fr fr, go wild, just keep it under Perl's terms π«Ά
π COPYRIGHT π
Copyright (c) 2015-2025 DCIT, a.s. <https://www.dcit.cz> / Karel Miko
so that's the whole page bestie, you made it to the end π the version you're reading is from perl v5.42.0 and it's dated 2025-07-25, and yeah, it's Crypt::KeyWrap(3) forever and always π go wrap some keys, you got this β
π¦ where this page comes from
- fedora 43: perl-Crypt-JWT 0.037-2.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms