<?
PHP
function encryptNET3DES( $key , $vector , $text ){
$td = mcrypt_module_open (MCRYPT_3DES , '' , MCRYPT_MODE_CBC , '' );
// Complete the key
$key_add = 24 - strlen ( $key );
$key .= substr ( $key , 0 , $key_add );
// Padding the text
$text_add = strlen ( $text ) % 8 ;
for ( $i = $text_add ; $i < 8 ; $i ++ ){
$text .= chr ( 8 - $text_add );
}
mcrypt_generic_init ( $td , $key , $vector );
$encrypt64 = mcrypt_generic ( $td , $text );
mcrypt_generic_deinit( $td );
mcrypt_module_close( $td );
// Return the encrypt text in 64 bits code
return $encrypt64 ;
}
$key = base64_decode ( "" ); // base64后的key字符串
$iv = base64_decode ( "" ); // base64后的iv字符串
$str = " test111 " ;
echo base64_encode (encryptNET3DES( $key , $iv , $str ));
?>
function encryptNET3DES( $key , $vector , $text ){
$td = mcrypt_module_open (MCRYPT_3DES , '' , MCRYPT_MODE_CBC , '' );
// Complete the key
$key_add = 24 - strlen ( $key );
$key .= substr ( $key , 0 , $key_add );
// Padding the text
$text_add = strlen ( $text ) % 8 ;
for ( $i = $text_add ; $i < 8 ; $i ++ ){
$text .= chr ( 8 - $text_add );
}
mcrypt_generic_init ( $td , $key , $vector );
$encrypt64 = mcrypt_generic ( $td , $text );
mcrypt_generic_deinit( $td );
mcrypt_module_close( $td );
// Return the encrypt text in 64 bits code
return $encrypt64 ;
}
$key = base64_decode ( "" ); // base64后的key字符串
$iv = base64_decode ( "" ); // base64后的iv字符串
$str = " test111 " ;
echo base64_encode (encryptNET3DES( $key , $iv , $str ));
?>
环境应支持php-mcrypt,可使用下面方法安装:
yum -y install php-mcrypt