Crypt::...:BLAKE2b(3)

πŸ’– NAME

okay so bestie, this is Crypt::Mac::BLAKE2b(3) from the User Contributed Perl Documentation corner of the internet, and it's literally the page for Crypt::Mac::BLAKE2b β€” Message authentication code BLAKE2b MAC (RFC 7693). That's the whole vibe: BLAKE2b MAC, but make it Perl. 🫢


✨ SYNOPSIS

bestie, here's the copy-paste buffet, exactly as the page serves it:

### Functional interface:
use Crypt::Mac::BLAKE2b qw( blake2b blake2b_hex blake2b_b64 blake2b_b64u );

# calculate MAC from string/buffer
my $blake2b_raw  = blake2b($size, $key, 'data buffer');
my $blake2b_hex  = blake2b_hex($size, $key, 'data buffer');
my $blake2b_b64  = blake2b_b64($size, $key, 'data buffer');
my $blake2b_b64u = blake2b_b64u($size, $key, 'data buffer');

### OO interface:
use Crypt::Mac::BLAKE2b;

my $d = Crypt::Mac::BLAKE2b->new($size, $key);
$d->add('any data');
my $result_hex = $d->hexmac;   # finalizes the object

# for another output encoding use a fresh object (or clone before finalizing)
my $result_b64u = Crypt::Mac::BLAKE2b->new($size, $key)->add('any data')->b64umac;

# or MAC a file instead
my $file_result_raw = Crypt::Mac::BLAKE2b->new($size, $key)->addfile('filename.dat')->mac;

πŸ’œ DESCRIPTION

This module gives you an interface to the BLAKE2b message authentication code (MAC) algorithm. It's giving "I do one thing and I do it with a whole lot of flair." πŸ’…


πŸ“¦ EXPORT

Nothing is exported by default. iconic behavior, honestly.

You can export selected functions like this:

use Crypt::Mac::BLAKE2b qw( blake2b blake2b_hex blake2b_b64 blake2b_b64u );

Or all of them at once, periodt:

use Crypt::Mac::BLAKE2b ':all';

🌈 FUNCTIONS

🫢 blake2b

Joins all arguments into a single string and returns its BLAKE2b message authentication code encoded as a binary string. raw bytes, no dressing.

Data arguments for the functional helpers are converted to byte strings using Perl's usual scalar stringification. Defined scalars, including numbers and string-overloaded objects, are accepted. undef is treated as an empty string and may emit Perl's usual "uninitialized value" warning. The same rules apply to blake2b_hex, blake2b_b64, and blake2b_b64u.

my $blake2b_raw = blake2b($size, $key, 'data buffer');
#or
my $blake2b_raw = blake2b($size, $key, 'any data', 'more data', 'even more data');

πŸ¦‹ blake2b_hex

Joins all arguments into a single string and returns its BLAKE2b message authentication code encoded as a hexadecimal string. lowercase hex, looking all neat and tidy.

my $blake2b_hex = blake2b_hex($size, $key, 'data buffer');
#or
my $blake2b_hex = blake2b_hex($size, $key, 'any data', 'more data', 'even more data');

πŸŽ€ blake2b_b64

Joins all arguments into a single string and returns its BLAKE2b message authentication code encoded as a Base64 string. cute, portable, classic.

my $blake2b_b64 = blake2b_b64($size, $key, 'data buffer');
#or
my $blake2b_b64 = blake2b_b64($size, $key, 'any data', 'more data', 'even more data');

🧚 blake2b_b64u

Joins all arguments into a single string and returns its BLAKE2b message authentication code encoded as a Base64 URL-safe string (see RFC 4648 section 5). yes bestie, URL-safe, no awkward characters crashing the party.

my $blake2b_b64url = blake2b_b64u($size, $key, 'data buffer');
#or
my $blake2b_b64url = blake2b_b64u($size, $key, 'any data', 'more data', 'even more data');

🌟 METHODS

Unless noted otherwise, assume $d is an existing MAC object created via new, for example:

my $d = Crypt::Mac::BLAKE2b->new($size, $key);

πŸ‘‘ new

my $d = Crypt::Mac::BLAKE2b->new($size, $key);

# $size .. [integer] desired MAC output size in bytes (1 - 64)
# $key ... [binary string] the key (1 - 64 bytes)

$size is your desired MAC output size in bytes, from 1 to 64. $key is the key, a binary string from 1 to 64 bytes. main character constructor energy. πŸŽ€

🐚 clone

the source page keeps this one short and sweet, so here's the exact signature, bestie:

$d->clone();

πŸ’« add

Appends data to the message. Returns the object itself (for chaining). Croaks if the object has already been finalized by mac, hexmac, b64mac, or b64umac.

Each argument is converted to bytes using Perl's usual scalar stringification. Defined scalars, including numbers and string-overloaded objects, are accepted. undef is treated as an empty string and may emit Perl's usual "uninitialized value" warning.

$d->add('any data');
#or
$d->add('any data', 'more data', 'even more data');

πŸ“ addfile

Reads the file content and appends it to the message. Returns the object itself (for chaining). Croaks if the object has already been finalized by mac, hexmac, b64mac, or b64umac.

$d->addfile('filename.dat');
#or
my $filehandle = ...; # existing binary-mode filehandle
$d->addfile($filehandle);

it's giving "MAC a file instead," and honestly? obsessed. πŸ”₯

πŸ’€ mac

Returns the binary MAC (raw bytes) and finalizes the object. After the first call to mac, hexmac, b64mac, or b64umac, later calls to add, addfile, or any MAC getter croak.

my $result_raw = $d->mac();

🌸 hexmac

Returns the MAC encoded as a lowercase hexadecimal string and finalizes the object. After the first call to mac, hexmac, b64mac, or b64umac, later calls to add, addfile, or any MAC getter croak.

my $result_hex = $d->hexmac();

πŸŽ€ b64mac

Returns the MAC encoded as a Base64 string with trailing = padding and finalizes the object. After the first call to mac, hexmac, b64mac, or b64umac, later calls to add, addfile, or any MAC getter croak.

my $result_b64 = $d->b64mac();

πŸ¦‹ b64umac

Returns the MAC encoded as a Base64 URL-safe string (no trailing =) and finalizes the object. After the first call to mac, hexmac, b64mac, or b64umac, later calls to add, addfile, or any MAC getter croak.

my $result_b64url = $d->b64umac();

πŸ‘€ SEE ALSO


okay that's the whole page, bestie. this sign-off is serving perl v5.42.0, dated 2026-05-11 β€” that's the source/version + date energy, and yes, we ate. πŸ’…βœ¨

πŸ“¦ where this page comes from