{
    "mode": "perldoc",
    "parameter": "Convert::PEM::CBC",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Convert%3A%3APEM%3A%3ACBC/json",
    "generated": "2026-06-15T18:40:00Z",
    "synopsis": "use Convert::PEM::CBC;\nmy $cbc = Convert::PEM::CBC->new(\nCipher     => 'Crypt::DESEDE3',\nPassphrase => 'foo'\n);\nmy $plaintext = 'foo bar baz';\n$cbc->encrypt($plaintext);",
    "sections": {
        "NAME": {
            "content": "Convert::PEM::CBC - Cipher Block Chaining Mode implementation\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Convert::PEM::CBC;\nmy $cbc = Convert::PEM::CBC->new(\nCipher     => 'Crypt::DESEDE3',\nPassphrase => 'foo'\n);\n\nmy $plaintext = 'foo bar baz';\n$cbc->encrypt($plaintext);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "*Convert::PEM::CBC* implements the CBC (Cipher Block Chaining) mode for encryption/decryption\nciphers; the CBC is designed for compatability with OpenSSL and may not be compatible with other\nimplementations (such as SSH).\n",
            "subsections": []
        },
        "USAGE": {
            "content": "$cbc = Convert::PEM::CBC->new(%args)\nCreates a new *Convert::PEM::CBC* object and initializes it. Returns the new object.\n\n*%args* can contain:\n\n*   Cipher\n\nEither the name of an encryption cipher class (eg. *Crypt::DES*), or an object already\nblessed into such a class. The class must support the *keysize*, *blocksize*, *encrypt*, and\n*decrypt* methods. If the value is a blessed object, it is assumed that the object has\nalready been initialized with a key.\n\nThis argument is mandatory.\n\n*   Passphrase\n\nA passphrase to encrypt/decrypt the content. This is different in implementation from a key\n(*Key*), because it is assumed that a passphrase comes directly from a user, and must be\nmunged into the correct form for a key. This \"munging\" is done by repeatedly computing an\nMD5 hash of the passphrase, the IV, and the existing hash, until the generated key is longer\nthan the keysize for the cipher (*Cipher*).\n\nBecause of this \"munging\", this argument can be any length (even an empty string).\n\nIf you give the *Cipher* argument an object, this argument is ignored. If the *Cipher*\nargument is a cipher class, either this argument or *Key* must be provided.\n\n*   Key\n\nA raw key, to be passed directly to the new cipher object. Because this is passed directly\nto the cipher itself, the length of the key must be equal to or greater than the keysize for\nthe *Cipher*.\n\nAs with the *Passphrase* argument, if you give the *Cipher* argument an already-constructed\ncipher object, this argument is ignored. If the *Cipher* argument is a cipher class, either\nthis argument or *Passphrase* must be provided.\n\n*   IV\n\nThe initialization vector for CBC mode.\n\nThis argument is optional; if not provided, a random IV will be generated. Obviously, if\nyou're decrypting data, you should provide this argument, because your IV should match the\nIV used to encrypt the data.\n\n$cbc->encrypt($plaintext)\nEncrypts the plaintext *$plaintext* using the underlying cipher implementation in CBC mode, and\nreturns the ciphertext.\n\nIf any errors occur, returns *undef*, and you should check the *errstr* method to find out what\nwent wrong.\n\n$cbc->decrypt($ciphertext)\nDecrypts the ciphertext *$ciphertext* using the underlying cipher implementation in CBC mode,\nand returns the plaintext.\n\nIf any errors occur, returns *undef*, and you should check the *errstr* method to find out what\nwent wrong.\n\n$cbc->iv\nReturns the current initialization vector. One use for this might be to grab the initial value\nof the IV if it's created randomly (ie. you haven't provided an *IV* argument to *new*):\n\nmy $cbc = Convert::PEM::CBC->new( Cipher => $cipher );\nmy $iv = $cbc->iv;   ## Generated randomly in 'new'.\n\n*Convert::PEM* uses this to write the IV to the PEM file when encrypting, so that it can be\nknown when trying to decrypt the file.\n\n$cbc->errstr\nReturns the value of the last error that occurred. This should only be considered meaningful\nwhen you've received *undef* from one of the functions above; in all other cases its relevance\nis undefined.\n\nAUTHOR & COPYRIGHTS\nPlease see the Convert::PEM manpage for author, copyright, and license information.\n",
            "subsections": []
        }
    },
    "summary": "Convert::PEM::CBC - Cipher Block Chaining Mode implementation",
    "flags": [],
    "examples": [],
    "see_also": []
}