1Convert::PEM::CBC(3)  User Contributed Perl Documentation Convert::PEM::CBC(3)
2
3
4

NAME

6       Convert::PEM::CBC - Cipher Block Chaining Mode implementation
7

SYNOPSIS

9           use Convert::PEM::CBC;
10           my $cbc = Convert::PEM::CBC->new(
11                                Cipher     => 'Crypt::DES_EDE3',
12                                Passphrase => 'foo'
13                  );
14
15           my $plaintext = 'foo bar baz';
16           $cbc->encrypt($plaintext);
17

DESCRIPTION

19       Convert::PEM::CBC implements the CBC (Cipher Block Chaining) mode for
20       encryption/decryption ciphers; the CBC is designed for compatability
21       with OpenSSL and may not be compatible with other implementations (such
22       as SSH).
23

USAGE

25   $cbc = Convert::PEM::CBC->new(%args)
26       Creates a new Convert::PEM::CBC object and initializes it.  Returns the
27       new object.
28
29       %args can contain:
30
31       •   Cipher
32
33           Either the name of an encryption cipher class (eg. Crypt::DES), or
34           an object already blessed into such a class. The class must support
35           the keysize, blocksize, encrypt, and decrypt methods. If the value
36           is a blessed object, it is assumed that the object has already been
37           initialized with a key.
38
39           This argument is mandatory.
40
41       •   Passphrase
42
43           A passphrase to encrypt/decrypt the content. This is different in
44           implementation from a key (Key), because it is assumed that a
45           passphrase comes directly from a user, and must be munged into the
46           correct form for a key. This "munging" is done by repeatedly
47           computing an MD5 hash of the passphrase, the IV, and the existing
48           hash, until the generated key is longer than the keysize for the
49           cipher (Cipher).
50
51           Because of this "munging", this argument can be any length (even an
52           empty string).
53
54           If you give the Cipher argument an object, this argument is
55           ignored. If the Cipher argument is a cipher class, either this
56           argument or Key must be provided.
57
58       •   Key
59
60           A raw key, to be passed directly to the new cipher object. Because
61           this is passed directly to the cipher itself, the length of the key
62           must be equal to or greater than the keysize for the Cipher.
63
64           As with the Passphrase argument, if you give the Cipher argument an
65           already-constructed cipher object, this argument is ignored. If the
66           Cipher argument is a cipher class, either this argument or
67           Passphrase must be provided.
68
69       •   IV
70
71           The initialization vector for CBC mode.
72
73           This argument is optional; if not provided, a random IV will be
74           generated. Obviously, if you're decrypting data, you should provide
75           this argument, because your IV should match the IV used to encrypt
76           the data.
77
78   $cbc->encrypt($plaintext)
79       Encrypts the plaintext $plaintext using the underlying cipher
80       implementation in CBC mode, and returns the ciphertext.
81
82       If any errors occur, returns undef, and you should check the errstr
83       method to find out what went wrong.
84
85   $cbc->decrypt($ciphertext)
86       Decrypts the ciphertext $ciphertext using the underlying cipher
87       implementation in CBC mode, and returns the plaintext.
88
89       If any errors occur, returns undef, and you should check the errstr
90       method to find out what went wrong.
91
92   $cbc->iv
93       Returns the current initialization vector. One use for this might be to
94       grab the initial value of the IV if it's created randomly (ie.  you
95       haven't provided an IV argument to new):
96
97           my $cbc = Convert::PEM::CBC->new( Cipher => $cipher );
98           my $iv = $cbc->iv;   ## Generated randomly in 'new'.
99
100       Convert::PEM uses this to write the IV to the PEM file when encrypting,
101       so that it can be known when trying to decrypt the file.
102
103   $cbc->errstr
104       Returns the value of the last error that occurred. This should only be
105       considered meaningful when you've received undef from one of the
106       functions above; in all other cases its relevance is undefined.
107

AUTHOR & COPYRIGHTS

109       Please see the Convert::PEM manpage for author, copyright, and license
110       information.
111
112
113
114perl v5.36.0                      2023-01-20              Convert::PEM::CBC(3)
Impressum