function __construct($cipher) { $this->cipher = $cipher; $this->key_size = mcrypt_module_get_algo_key_size($cipher); $this->block_size = mcrypt_module_get_algo_block_size($cipher); $this->iv = str_repeat("", mcrypt_get_iv_size($cipher, 'ncfb')); }
<?php var_dump(mcrypt_module_get_algo_block_size(MCRYPT_RIJNDAEL_256)); var_dump(mcrypt_module_get_algo_block_size(MCRYPT_RIJNDAEL_192)); var_dump(mcrypt_module_get_algo_block_size(MCRYPT_RC2)); var_dump(mcrypt_module_get_algo_block_size(MCRYPT_XTEA)); var_dump(mcrypt_module_get_algo_block_size(MCRYPT_CAST_128)); var_dump(mcrypt_module_get_algo_block_size(MCRYPT_BLOWFISH));
$td = mcrypt_module_open("rijndael-256", "", "ofb", ""); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM); $ks = mcrypt_enc_get_key_size($td); $key = substr(md5("very secret key"), 0, $ks); mcrypt_generic_init($td, $key, $iv); $encrypted = mcrypt_generic($td, "This is very important data"); VERIFY($encrypted !== "This is very important data"); mcrypt_generic_deinit($td); mcrypt_generic_init($td, $key, $iv); $decrypted = mdecrypt_generic($td, $encrypted); mcrypt_generic_end($td); mcrypt_module_close($td); VS($decrypted, "This is very important data"); VERIFY(in_array("blowfish", mcrypt_list_algorithms())); VERIFY(in_array("cbc", mcrypt_list_modes())); VS(mcrypt_module_get_algo_block_size("blowfish"), 8); VS(mcrypt_module_get_algo_key_size("blowfish"), 56); VS(mcrypt_module_get_supported_key_sizes("blowfish"), array()); VS(mcrypt_module_get_supported_key_sizes("twofish"), array(16, 24, 32)); VS(mcrypt_module_is_block_algorithm_mode("cbc"), true); VS(mcrypt_module_is_block_algorithm("blowfish"), true); VS(mcrypt_module_is_block_mode("cbc"), true); VS(mcrypt_module_self_test(MCRYPT_RIJNDAEL_128), true); VS(mcrypt_module_self_test("bogus"), false); $text = "boggles the inivisble monkey will rule the world"; $key = "very secret key"; $iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $enc = mcrypt_encrypt(MCRYPT_XTEA, $key, $text, MCRYPT_MODE_ECB, $iv); VS(bin2hex($enc), "f522c62002fa16129c8576bcddc6dd0f7ea81991103ba42962d94c8bfff3ee660d53b187d7e989540abf5a729c2f7baf"); $crypttext = mcrypt_decrypt(MCRYPT_XTEA, $key, $enc, MCRYPT_MODE_ECB, $iv);