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