Crypt::...XChaCha(3)

✨ NAME ✨

okay bestie, welcome to the Crypt::...XChaCha(3) page β€” yes, a User Contributed Perl Documentation page β€” and the main character is Crypt::Stream::XChaCha: the stream cipher XChaCha20. πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

use Crypt::Stream::XChaCha;

# encrypt
my $key    = "12345678901234567890123456789012";  # 32 bytes
my $nonce  = "123456789012345678901234";          # 24 bytes
my $enc_stream = Crypt::Stream::XChaCha->new($key, $nonce);
my $ct = $enc_stream->crypt("plain message");

# decrypt
my $dec_stream = Crypt::Stream::XChaCha->new($key, $nonce);
my $pt = $dec_stream->crypt($ct);

🌸 DESCRIPTION 🌸

Since: CryptX-0.089 β€” noted, bestie. ✨

This gives you an interface to the XChaCha20 stream cipher, which is an extended-nonce variant of ChaCha20 using a 192-bit (24-byte) nonce. Lowkey iconic. πŸŽ€

πŸ’… METHODS πŸ’…

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

my $stream = Crypt::Stream::XChaCha->new($key, $nonce);

πŸŽ€ new πŸŽ€

my $stream = Crypt::Stream::XChaCha->new($key, $nonce);
#or
my $stream = Crypt::Stream::XChaCha->new($key, $nonce, $rounds);

# $key    .. [binary string] 32 bytes
# $nonce  .. [binary string] 24 bytes
# $rounds .. [integer] optional, rounds (DEFAULT: 20)
  • $key β€” [binary string] 32 bytes.
  • $nonce β€” [binary string] 24 bytes.
  • $rounds β€” [integer] optional, rounds (DEFAULT: 20).

πŸ”₯ crypt πŸ”₯

Encrypts or decrypts data. The output has the same length as the input. Returns a binary string (raw bytes). πŸ’–

The input is converted using Perl's usual scalar stringification. Passing undef is treated as an empty string with the usual warning, and numeric scalars are stringified before processing.

my $ciphertext = $stream->crypt($plaintext);
#or
my $plaintext = $stream->crypt($ciphertext);

🌟 keystream 🌟

Returns $length bytes of raw keystream as a binary string. πŸ’«

The length is taken using Perl's usual numeric coercion. Values that coerce to an oversized unsigned length are rejected as too large. No sneaky giant lengths, periodt. πŸ”₯

my $random_bytes = $stream->keystream($length);

πŸ¦‹ clone πŸ¦‹

Returns a copy of the stream cipher object in its current state. Snapshot slay. πŸ“Έ

my $stream2 = $stream->clone;

🌈 SEE ALSO 🌈


xoxo πŸ’– this page is perl v5.42.0, dated 2026-05-11, and it's the Crypt::...XChaCha(3) manual. periodt ✨

πŸ“¦ where this page comes from