{
    "mode": "perldoc",
    "parameter": "Crypt::Mode::CBC",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Crypt%3A%3AMode%3A%3ACBC/json",
    "generated": "2026-06-09T14:09:25Z",
    "synopsis": "use Crypt::Mode::CBC;\nmy $m = Crypt::Mode::CBC->new('AES');\n#(en|de)crypt at once\nmy $ciphertext = $m->encrypt($plaintext, $key, $iv);\nmy $plaintext = $m->decrypt($ciphertext, $key, $iv);\n#encrypt more chunks\n$m->startencrypt($key, $iv);\nmy $ciphertext = $m->add('some data');\n$ciphertext .= $m->add('more data');\n$ciphertext .= $m->finish;\n#decrypt more chunks\n$m->startdecrypt($key, $iv);\nmy $plaintext = $m->add($someciphertext);\n$plaintext .= $m->add($moreciphertext);\n$plaintext .= $m->finish;",
    "sections": {
        "NAME": {
            "content": "Crypt::Mode::CBC - Block cipher mode CBC [Cipher-block chaining]\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Crypt::Mode::CBC;\nmy $m = Crypt::Mode::CBC->new('AES');\n\n#(en|de)crypt at once\nmy $ciphertext = $m->encrypt($plaintext, $key, $iv);\nmy $plaintext = $m->decrypt($ciphertext, $key, $iv);\n\n#encrypt more chunks\n$m->startencrypt($key, $iv);\nmy $ciphertext = $m->add('some data');\n$ciphertext .= $m->add('more data');\n$ciphertext .= $m->finish;\n\n#decrypt more chunks\n$m->startdecrypt($key, $iv);\nmy $plaintext = $m->add($someciphertext);\n$plaintext .= $m->add($moreciphertext);\n$plaintext .= $m->finish;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module implements CBC cipher mode. NOTE: it works only with ciphers from CryptX\n(Crypt::Cipher::NNNN).\n",
            "subsections": []
        },
        "METHODS": {
            "content": "new\nmy $m = Crypt::Mode::CBC->new($name);\n#or\nmy $m = Crypt::Mode::CBC->new($name, $padding);\n#or\nmy $m = Crypt::Mode::CBC->new($name, $padding, $cipherrounds);\n\n# $name ....... one of 'AES', 'Anubis', 'Blowfish', 'CAST5', 'Camellia', 'DES', 'DESEDE',\n#               'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6',\n#               'SAFERP', 'SAFERK128', 'SAFERK64', 'SAFERSK128', 'SAFERSK64',\n#               'SEED', 'Skipjack', 'Twofish', 'XTEA', 'IDEA', 'Serpent'\n#               simply any <NAME> for which there exists Crypt::Cipher::<NAME>\n# $padding .... 0 no padding (plaintext size has to be multiple of block length)\n#               1 PKCS5 padding, Crypt::CBC's \"standard\" - DEFAULT\n#               2 Crypt::CBC's \"oneandzeroes\"\n#               3 ANSI X.923 padding\n#               4 zero padding\n#               5 zero padding (+a block of zeros if the output length is divisible by the blocksize)\n# $cipherrounds ... optional num of rounds for given cipher\n\nencrypt\nmy $ciphertext = $m->encrypt($plaintext, $key, $iv);\n\ndecrypt\nmy $plaintext = $m->decrypt($ciphertext, $key, $iv);\n\nstartencrypt\n$m->startencrypt($key, $iv);\n\nstartdecrypt\n$m->startdecrypt($key, $iv);\n\nadd\n# in encrypt mode\nmy $plaintext = $m->add($ciphertext);\n\n# in decrypt mode\nmy $ciphertext = $m->add($plaintext);\n\nfinish\n#encrypt more chunks\n$m->startencrypt($key, $iv);\nmy $ciphertext = '';\n$ciphertext .= $m->add('some data');\n$ciphertext .= $m->add('more data');\n$ciphertext .= $m->finish;\n\n#decrypt more chunks\n$m->startdecrypt($key, $iv);\nmy $plaintext = '';\n$plaintext .= $m->add($someciphertext);\n$plaintext .= $m->add($moreciphertext);\n$plaintext .= $m->finish;\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "*   CryptX, Crypt::Cipher\n\n*   Crypt::Cipher::AES, Crypt::Cipher::Blowfish, ...\n\n*   <https://en.wikipedia.org/wiki/Blockciphermodeofoperation#Cipher-blockchaining.28CBC.2\n9>\n",
            "subsections": []
        }
    },
    "summary": "Crypt::Mode::CBC - Block cipher mode CBC [Cipher-block chaining]",
    "flags": [],
    "examples": [],
    "see_also": []
}