Conver...EM::CBC(3pm)
π NAME π
Convert::PEM::CBC β the Cipher Block Chaining Mode implementation, and yes she's that girl π
This is the User Contributed Perl Documentation for it (section 3pm), and honestly? iconic. Let's get into it bestie β¨
πΈ SYNOPSIS πΈ
use Convert::PEM::CBC;
my $cbc = Convert::PEM::CBC->new(
Cipher => 'Crypt::DES_EDE3',
Passphrase => 'foo'
);
my $plaintext = 'foo bar baz';
$cbc->encrypt($plaintext);
Look at her. So simple. So clean. We love a low-effort high-reward moment π«Ά
π¦ DESCRIPTION π¦
So Convert::PEM::CBC implements the CBC (Cipher Block Chaining) mode for encryption/decryption ciphers. That's the whole vibe.
But here's the thing you need to know, and I'm saying it with my whole chest: this CBC is designed for compatibility with OpenSSL, and it may not be compatible with other implementations (such as SSH). So likeβ¦ if you try to mix and match, it's giving chaos, not slay. No cap π
π USAGE π
β¨ $cbc = Convert::PEM::CBC->new(%args) β¨
Makes you a brand new Convert::PEM::CBC object and initializes it. Returns the new object. Periodt π
%args can contain:
Cipherβ Either the name of an encryption cipher class (eg.Crypt::DES), or an object already blessed into such a class. The class must support thekeysize,blocksize,encrypt, anddecryptmethods. If the value is a blessed object, it is assumed that the object has already been initialized with a key.
This argument is mandatory. No Cipher, no party. π«
Passphraseβ A passphrase to encrypt/decrypt the content. Now listen, this is different in implementation from a key (Key), because it's assumed that a passphrase comes directly from a user, and must be munged into the correct form for a key. This "munging" is done by repeatedly computing an MD5 hash of the passphrase, the IV, and the existing hash, until the generated key is longer than thekeysizefor the cipher (Cipher).
Because of this "munging", this argument can be any length (even an empty string). She's flexible like that π
If you give the Cipher argument an object, this argument is ignored. If the Cipher argument is a cipher class, either this argument or Key must be provided.
Keyβ A raw key, to be passed directly to the new cipher object. Because this is passed directly to the cipher itself, the length of the key must be equal to or greater than thekeysizefor theCipher.
As with the Passphrase argument, if you give the Cipher argument an already-constructed cipher object, this argument is ignored. If the Cipher argument is a cipher class, either this argument or Passphrase must be provided.
IVβ The initialization vector for CBC mode.
This argument is optional; if not provided, a random IV will be generated. Obviously, if you're decrypting data, you should provide this argument, because your IV should match the IV used to encrypt the data. (Like, obviously. Come on now π)
π₯ $cbc->encrypt($plaintext) π₯
Encrypts the plaintext $plaintext using the underlying cipher implementation in CBC mode, and returns the ciphertext. Chef's kiss π
If any errors occur, it returns undef, and you should check the errstr method to find out what went wrong.
π $cbc->decrypt($ciphertext) π
Decrypts the ciphertext $ciphertext using the underlying cipher implementation in CBC mode, and returns the plaintext. The reverse glow-up β¨
If any errors occur, it returns undef, and you should check the errstr method to find out what went wrong.
π§ $cbc->iv π§
Returns the current initialization vector. One use for this might be to grab the initial value of the IV if it's created randomly (ie. you haven't provided an IV argument to new):
my $cbc = Convert::PEM::CBC->new( Cipher => $cipher );
my $iv = $cbc->iv; ## Generated randomly in 'new'.
Convert::PEM uses this to write the IV to the PEM file when encrypting, so that it can be known when trying to decrypt the file. Teamwork makes the dream work π«Ά
π $cbc->errstr π
Returns the value of the last error that occurred. This should only be considered meaningful when you've received undef from one of the functions above; in all other cases its relevance is undefined. So like, don't read into it when everything's fine, bestie β she's not being cryptic, you're just asking out of context π
π AUTHOR & COPYRIGHTS π
Please see the Convert::PEM manpage for author, copyright, and license information. All the receipts are over there, fr fr π
And that's the whole page! perl v5.40.0, dated 2024-12-03 β thanks for reading, mwah πππ¦
π¦ where this page comes from
- debian trixie: libconvert-pem-perl 0.13-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libconvert-pem-perl 0.13-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libconvert-pem-perl 0.13-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms