Skip to main content

PHP script to list what ciphers, modes, key, block and iv sizes are supported on your server.

<?php

/**
 * See what ciphers, modes, key, block and iv sizes are supported on your server
 *
 * If you want a quick way to see what ciphers, modes, key, block and iv sizes
 * are supported on your server, try something like the following.
 *
 * Note: I used this simple bash: `locate libmcrypt` from terminal on Mac
 * OS X to determine the install paths to the algorithms and modes directories.
 * Lots of function calls generate warnings for certain ciphers, hence the use
 * of error suppression.
 *
 * http://php.net/manual/en/book.mcrypt.php
 */
function showEncryptionSupported() {

    $modes = mcrypt_list_modes();
    $algorithms = mcrypt_list_algorithms();

    foreach ($algorithms as $cipher) {

        echo "<br><hr><h1 style=\"padding: 10px; color: green\">" . $cipher . "</h1>\n";

        foreach ($modes as $mode) {
            echo "<h2>" . $mode . "</h2>\n";

            @$td = mcrypt_module_open($cipher, '/usr/local/libmcrypt-2.5.8/modules/algorithms/', $mode, '/usr/local/libmcrypt-2.5.8/modules/modes/');
            @$key_size = mcrypt_enc_get_key_size($td);
            @$block_size = mcrypt_get_block_size($cipher, $mode);
            @$iv_size = mcrypt_get_iv_size($cipher, $mode);
            @mcrypt_module_close($td);

            echo "
        <pre>
            key_size: " . ($key_size ? $key_size : 'n/a') . "    block_size: " . ($block_size ? $block_size : 'n/a') . "    iv_size: " . ($iv_size ? $iv_size : 'n/a') . "  </pre>\n\n";

            $td = NULL;
            $key_size = NULL;
            $block_size = NULL;
            $iv_size = NULL;
        }
    }
}

showEncryptionSupported();

?>