Crypt::Cipher(3)
π NAME π
omg hiiii bestie π welcome to Crypt::Cipher(3) β the manual page for Crypt::Cipher, aka your generic interface to cipher functions β¨ like, it's giving βone API to rule the symmetric ciphersβ and we're obsessed π
β¨ SYNOPSIS β¨
okay so here's the vibe check, bestie π«Ά three little examples, all copied exactly because details matter:
#### example 1 (encrypting single block)
use Crypt::Cipher;
my $key = '1234567890abcdef'; # 16 bytes, valid for AES-128
my $plaintext_block = '1234567890123456'; # one AES block (16 bytes)
my $c = Crypt::Cipher->new('AES', $key);
my $blocksize = $c->blocksize;
my $ciphertext = $c->encrypt($plaintext_block); # encrypt 1 block
my $plaintext = $c->decrypt($ciphertext); #decrypt 1 block
### example 2 (using CBC mode)
use Crypt::Mode::CBC;
my $cbc_key = '1234567890abcdef'; # 16 bytes, valid for AES-128
my $iv = 'fedcba0987654321'; # 16 bytes
my $cbc = Crypt::Mode::CBC->new('AES');
my $cbc_ciphertext = $cbc->encrypt("secret data", $cbc_key, $iv);
#### example 3 (compatibility with Crypt::CBC)
use Crypt::CBC;
use Crypt::Cipher;
my $compat_key = '1234567890abcdef'; # 16 bytes, valid for AES-128
my $compat_iv = 'fedcba0987654321'; # 16 bytes
my $cipher = Crypt::Cipher->new('AES', $compat_key);
my $compat_cbc = Crypt::CBC->new( -cipher=>$cipher, -iv=>$compat_iv );
my $compat_ciphertext = $compat_cbc->encrypt("secret data");
π¦ DESCRIPTION π¦
So like, Crypt::Cipher gives you an interface to various symmetric cipher algorithms πΈ it's the main character that lets you talk to a whole little family of ciphers, iykyk π
β οΈ real talk, bestie: this module only implements single-block encryption and decryption π for general data, use a block mode such asCrypt::Mode::CBC,Crypt::Mode::CTR, orCrypt::CBC(which is slower) π
π METHODS π
Unless it says otherwise, just assume $c is an existing cipher object you already made via new, like this:
my $c = Crypt::Cipher->new('AES', '1234567890abcdef');
π new
Constructor vibes β¨ returns a reference to the cipher object, periodt.
## basic scenario
my $c = Crypt::Cipher->new($name, $key);
# $name = one of 'AES', 'Anubis', 'Blowfish', 'CAST5', 'Camellia', 'DES', 'DES_EDE',
# 'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6',
# 'SAFERP', 'SAFER_K128', 'SAFER_K64', 'SAFER_SK128', 'SAFER_SK64',
# 'SEED', 'SM4', 'Skipjack', 'Twofish', 'XTEA', 'IDEA', 'Serpent'
# or any <NAME> for which there is a Crypt::Cipher::<NAME> module
# $key = binary key (keysize should comply with selected cipher requirements)
## some of the ciphers (e.g. MULTI2, RC5, SAFER) allow one to set number of rounds
my $c = Crypt::Cipher->new('MULTI2', $key, $rounds);
# $rounds = positive integer (should comply with selected cipher requirements)
π encrypt
Encrypts $plaintext and returns $ciphertext π₯ an empty string is accepted and returned unchanged; otherwise $plaintext must be exactly blocksize bytes long, no cap.
my $ciphertext = $c->encrypt($plaintext);
π decrypt
Decrypts $ciphertext and returns $plaintext π an empty string is accepted and returned unchanged; otherwise $ciphertext must be exactly blocksize bytes long, bestie.
my $plaintext = $c->decrypt($ciphertext);
π keysize
Just an alias for max_keysize β needed for Crypt::CBC compatibility π«Ά that's literally it.
π max_keysize
Returns the maximum allowed key size in bytes for the given cipher β¨
$c->max_keysize;
#or
Crypt::Cipher->max_keysize('AES');
#or
Crypt::Cipher::max_keysize('AES');
π min_keysize
Returns the minimum allowed key size in bytes for the given cipher πΈ
$c->min_keysize;
#or
Crypt::Cipher->min_keysize('AES');
#or
Crypt::Cipher::min_keysize('AES');
π§± blocksize
Returns the block size in bytes for the given cipher π
$c->blocksize;
#or
Crypt::Cipher->blocksize('AES');
#or
Crypt::Cipher::blocksize('AES');
π default_rounds
Returns the default number of rounds for the given cipher β only some ciphers, such as MULTI2, RC5, and SAFER, let you set the number of rounds via new().
$c->default_rounds;
#or
Crypt::Cipher->default_rounds('AES');
#or
Crypt::Cipher::default_rounds('AES');
π SEE ALSO π
CryptXβ go look, bestie β¨- See subclasses such as
Crypt::Cipher::AES,Crypt::Cipher::Blowfish, ... π
okay thatβs the whole page, bestie π«Ά this little manpage was brought to you by perl v5.42.0, dated 2026-05-11, and itβs literally Crypt::Cipher(3) signing off π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms