Crypt::Mode::CFB(3)

πŸ’œ Crypt::Mode::CFB(3) β€” bestie edition πŸ’œ

okay so this is a User Contributed Perl Documentation page for Crypt::Mode::CFB, and honestly? it's a whole vibe. stick with me, we're gonna get through it together 🫢


✨ NAME ✨

Crypt::Mode::CFB β€” the block cipher mode CFB, which stands for Cipher feedback. yes bestie, feedback like a microphone, but for bytes 🎀


🌸 SYNOPSIS 🌸

here's the whole flex, look at her go:

use Crypt::Mode::CFB;
my $m = Crypt::Mode::CFB->new('AES');
my $key = '1234567890123456';
my $iv = '1234567890123456';
my $plaintext = 'example plaintext';
my $chunk1 = 'example ';
my $chunk2 = 'plaintext';

# encrypt or decrypt in one call
my $single_ciphertext = $m->encrypt($plaintext, $key, $iv);
my $single_plaintext = $m->decrypt($single_ciphertext, $key, $iv);

# encrypt more chunks
$m->start_encrypt($key, $iv);
my $chunked_ciphertext = '';
$chunked_ciphertext .= $m->add($chunk1);
$chunked_ciphertext .= $m->add($chunk2);

# decrypt more chunks
$m->start_decrypt($key, $iv);
my $chunked_plaintext = '';
$chunked_plaintext .= $m->add($chunked_ciphertext);

like, one-and-done or chunk-by-chunk? she does both. main character energy fr πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

this module implements the CFB cipher mode. it's giving "streaming, no padding, zero drama."

⚠️ important bestie note straight from the source: it works only with ciphers from CryptX, i.e. Crypt::Cipher::NNNN. don't come at her with anything else, she will not know her πŸ’€

πŸŽ€ METHODS πŸŽ€

unless it says otherwise, just assume $m is a mode object that already exists, made via new, like this:

my $m = Crypt::Mode::CFB->new('AES');

🌈 new

my $m = Crypt::Mode::CFB->new($name);
#or
my $m = Crypt::Mode::CFB->new($name, $cipher_rounds);

# $name ............ [string] 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', 'Skipjack', 'Twofish', 'XTEA', 'IDEA', 'Serpent'
#                    or any <NAME> for which there is a Crypt::Cipher::<NAME> module
# $cipher_rounds ... [integer] optional, number of rounds for given cipher
  • $name β€” a string, one of the cipher names listed above, or literally any <NAME> that has a Crypt::Cipher::<NAME> module out there. the roster is stacked, ngl πŸ‘‘
  • $cipher_rounds β€” an integer, optional, the number of rounds for that cipher. only if you're feeling fancy ✨

πŸ”₯ encrypt

encrypts the plaintext in one single call, no warm-up. hands you back the ciphertext as a binary string πŸ’–

heads up on the conversion lore: the plaintext scalar gets turned into bytes using Perl's usual scalar stringification. defined scalars are all good β€” numbers, string-overloaded objects, all of it. undef gets treated as an empty string and might emit Perl's usual "uninitialized value" warning. πŸ™ˆ

my $ciphertext = $m->encrypt($plaintext, $key, $iv);

⭐ decrypt

same deal but backwards β€” decrypts the ciphertext in one single call and returns the plaintext as a binary string.

again: the ciphertext scalar is converted to bytes with Perl's usual scalar stringification, defined scalars (numbers, string-overloaded objects) are accepted, and undef is treated as an empty string and may emit Perl's usual "uninitialized value" warning. no cap 🧚

my $plaintext = $m->decrypt($ciphertext, $key, $iv);

πŸ’« start_encrypt

initializes encryption mode. returns the object itself, so she's chainable, she's generous, she's that girl πŸ’…

$m->start_encrypt($key, $iv);

πŸ“ start_decrypt

initializes decryption mode. also returns the object itself. symmetric queen 🌸

$m->start_decrypt($key, $iv);

🌟 add

feeds data into the encryption or decryption stream. returns a binary string, always.

each argument gets converted to bytes using Perl's usual scalar stringification β€” defined scalars incl. numbers and string-overloaded objects are welcome, undef is treated as an empty string and may emit Perl's usual "uninitialized value" warning. same rules, every time, periodt πŸ’€

# in encrypt mode
my $ciphertext = $m->add($plaintext);

# in decrypt mode
my $plaintext = $m->add($ciphertext);

πŸ’Ž finish

okay so CFB is a streaming mode and does not use padding, which means finish returns an empty string. that's not a bug bestie, that's the whole point 😌

she exists purely for API consistency with Crypt::Mode::CBC and Crypt::Mode::ECB, and you may safely call her or just… not. both are iconic 🫢

$m->start_encrypt($key, $iv);
my $ciphertext = '';
$ciphertext .= $m->add($chunk1);
$ciphertext .= $m->add($chunk2);
$ciphertext .= $m->finish;   # returns ''

πŸ‘‘ SEE ALSO πŸ‘‘


and that's the page, bestie!! πŸ¦‹ run it back any time πŸ’–

perl v5.42.0 ✨ 2026-05-11 ✨ Crypt::Mode::CFB(3) β€” that's the version and the date down at the bottom, mwah πŸ’‹ go encrypt something gorgeous 🌈

πŸ“¦ where this page comes from