加密函数:string mcrypt_encrypt ( string $cipher
, string $key
, string $data
, string $mode
[, string $iv
] )
解密函数:string mcrypt_decrypt ( string $cipher
, string $key
, string $data
, string $mode
[, string $iv
] )
# $cipher:算法名称,有些算法名称是在某些平台上不能使用,下面列出这里可用的算法名称 MCRYPT_3DES、MCRYPT_ARCFOUR_IV (libmcrypt > 2.4.x only)、 MCRYPT_ARCFOUR (libmcrypt > 2.4.x only)、MCRYPT_BLOWFISH、MCRYPT_CAST_128、 MCRYPT_CAST_256、MCRYPT_CRYPT、MCRYPT_DES、MCRYPT_DES_COMPAT (libmcrypt 2.2.x only)、 MCRYPT_ENIGMA (libmcrypt > 2.4.x only, alias for MCRYPT_CRYPT)、MCRYPT_GOST、 MCRYPT_IDEA (non-free)、MCRYPT_LOKI97 (libmcrypt > 2.4.x only)、 MCRYPT_MARS (libmcrypt > 2.4.x only, non-free)、MCRYPT_PANAMA (libmcrypt > 2.4.x only)、 MCRYPT_RIJNDAEL_128 (libmcrypt > 2.4.x only)、 MCRYPT_RIJNDAEL_192 (libmcrypt > 2.4.x only)、 MCRYPT_RIJNDAEL_256 (libmcrypt > 2.4.x only)、 MCRYPT_RC2、MCRYPT_RC4 (libmcrypt 2.2.x only)、MCRYPT_RC6 (libmcrypt > 2.4.x only)、 MCRYPT_RC6_128 (libmcrypt 2.2.x only)、MCRYPT_RC6_192 (libmcrypt 2.2.x only)、 MCRYPT_RC6_256 (libmcrypt 2.2.x only)、MCRYPT_SAFER64、MCRYPT_SAFER128、 MCRYPT_SAFERPLUS (libmcrypt > 2.4.x only)、MCRYPT_SERPENT(libmcrypt > 2.4.x only)、 MCRYPT_SERPENT_128 (libmcrypt 2.2.x only)、MCRYPT_SERPENT_192 (libmcrypt 2.2.x only)、 MCRYPT_SERPENT_256 (libmcrypt 2.2.x only)、MCRYPT_SKIPJACK (libmcrypt > 2.4.x only)、 MCRYPT_TEAN (libmcrypt 2.2.x only)、MCRYPT_THREEWAY、 MCRYPT_TRIPLEDES (libmcrypt > 2.4.x only)、 MCRYPT_TWOFISH (for older mcrypt 2.x versions, or mcrypt > 2.4.x )、 MCRYPT_TWOFISH192、MCRYPT_TWOFISH256、MCRYPT_WAKE (libmcrypt > 2.4.x only)、 MCRYPT_XTEA (libmcrypt > 2.4.x only)
# $key:加密时的密钥,不要超过当前算法所支持的最大的密钥长度
# $data:需要加密的数据
# $mode:加密的模式,MCRYPT_MODE_ECB、MCRYPT_MODE_CBC、MCRYPT_MODE_CFB、MCRYPT_MODE_OFB MCRYPT_MODE_NOFB、MCRYPT_MODE_STREAM
使用方法:
<?php $size = mcrypt_get_key_size( MCRYPT_DES, MCRYPT_MODE_ECB ); $key = substr( md5( 'RARONE' ), 0, $size ); $encode = mcrypt_encrypt( MCRYPT_DES, $key, 'Cherish', MCRYPT_MODE_ECB ); echo $encode, PHP_EOL; --对Cherish加密后的数据 echo mcrypt_decrypt( MCRYPT_DES, $key, $encode, MCRYPT_MODE_ECB ); --解密后的结果
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。