使用
初始化向量,需要传入IV大小和IV源
$cipher = MCRYPT_DES; //密码类型 $modes = MCRYPT_MODE_ECB; //密码模式 $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher,$modes),MCRYPT_RAND);//初始化向量
加密
$str_encrypt = mcrypt_encrypt($cipher,$key,$str,$modes,$iv); //加密函数
解密
$str_decrypt = mcrypt_decrypt($cipher,$key,$str_encrypt,$modes,$iv); //解密函数
支持的密码类型
define ('MCRYPT_3DES', "tripledes"); define ('MCRYPT_ARCFOUR_IV', "arcfour-iv"); define ('MCRYPT_ARCFOUR', "arcfour"); define ('MCRYPT_BLOWFISH', "blowfish"); define ('MCRYPT_BLOWFISH_COMPAT', "blowfish-compat"); define ('MCRYPT_CAST_128', "cast-128"); define ('MCRYPT_CAST_256', "cast-256"); define ('MCRYPT_CRYPT', "crypt"); define ('MCRYPT_DES', "des"); define ('MCRYPT_ENIGNA', "crypt"); define ('MCRYPT_GOST', "gost"); define ('MCRYPT_LOKI97', "loki97"); define ('MCRYPT_PANAMA', "panama"); define ('MCRYPT_RC2', "rc2"); define ('MCRYPT_RIJNDAEL_128', "rijndael-128"); define ('MCRYPT_RIJNDAEL_192', "rijndael-192"); define ('MCRYPT_RIJNDAEL_256', "rijndael-256"); define ('MCRYPT_SAFER64', "safer-sk64"); define ('MCRYPT_SAFER128', "safer-sk128"); define ('MCRYPT_SAFERPLUS', "saferplus"); define ('MCRYPT_SERPENT', "serpent"); define ('MCRYPT_THREEWAY', "threeway"); define ('MCRYPT_TRIPLEDES', "tripledes"); define ('MCRYPT_TWOFISH', "twofish"); define ('MCRYPT_WAKE', "wake"); define ('MCRYPT_XTEA', "xtea"); define ('MCRYPT_IDEA', "idea"); define ('MCRYPT_MARS', "mars"); define ('MCRYPT_RC6', "rc6"); define ('MCRYPT_SKIPJACK', "skipjack”);
支持的密码模式
define ('MCRYPT_MODE_CBC', "cbc"); define ('MCRYPT_MODE_CFB', "cfb"); define ('MCRYPT_MODE_ECB', "ecb"); define ('MCRYPT_MODE_NOFB', "nofb"); define ('MCRYPT_MODE_OFB', "ofb"); define ('MCRYPT_MODE_STREAM', "stream”);