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 as Crypt::Mode::CBC, Crypt::Mode::CTR, or Crypt::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