mcrypt的优点不仅仅在于其提供的加密算法较多,在windows下随PHP包一起发布,还在于它可以对数据进行加/解密处理,此外,它还提供了包括DES算法在内的35种处理数据用的函数。
08 | function authCrypt( $date , $key , $mode = 'encode' ) { |
09 | if ( $mode == 'decode' ) { |
10 | $date = base64_decode ( $date ); |
12 | if (function_exists( 'mcrypt_create_iv' )) { |
13 | $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); |
14 | $iv = mcrypt_create_iv( $iv_size , MCRYPT_RAND); |
16 | if (isset( $iv ) && $mode == 'encode' ) { |
17 | $passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key , $date , MCRYPT_MODE_ECB, $iv ); |
18 | } elseif (isset( $iv ) && $mode == 'decode' ) { |
19 | $passcrypt = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key , $date , MCRYPT_MODE_ECB, $iv ); |
21 | if ( $mode == 'encode' ) { |
22 | $passcrypt = base64_encode ( $passcrypt ); |