function crypt()
{
$key = "roman_2010";
$input = "1234560";
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$encrypted_data = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
echo "Encrypt: ".$encrypted_data=base64_encode($encrypted_data);
echo "<br><br>";
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
mcrypt_generic_init($td, $key, $iv);
//$encrypted_data2='vScZH7WJl0c=';
$encrypted_data2=base64_decode('vScZH7WJl0c=');//$encrypted_data
$decrypted_data = mdecrypt_generic($td,$encrypted_data2);
echo "Decrypt: ".$decrypted_data;
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$encrypted_data3 = mcrypt_generic($td, $decrypted_data);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$encrypted_data3=base64_encode($encrypted_data3);
echo '<br/>******encrypted_data**********<br>';
echo $encrypted_data;
echo '<br/>******encrypted_data3**********<br>';
echo $encrypted_data3;
echo '<br/>';
if($encrypted_data==$encrypted_data3){
echo '111111111';
}else{
echo '000000000';
}
}
function crypt2()
{
$text = "12345689";
$key = "roman_2010_test";
//***key有max長度為16的限制
$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);
echo '<br/>******enc**********<br>';
echo strlen($enc).'----'.$enc;
echo '<br/>';
echo $enc=base64_encode($enc); //aVVnGoiB07w=
$enc2=base64_decode($enc);
$crypttext = mcrypt_decrypt(MCRYPT_XTEA, $key, $enc2, MCRYPT_MODE_ECB, $iv);
echo '<br/>******crypttext**********<br>';
echo $crypttext;
$crypt_text = mcrypt_encrypt(MCRYPT_XTEA, $key, $crypttext, MCRYPT_MODE_ECB, $iv);
echo '<br/>******crypt_text**********<br>';
echo $crypt_text;
echo '<br/>';
echo $crypt_text=base64_encode($crypt_text); //aVVnGoiB07w=
echo '<br/>';
if($crypt_text==$enc){
echo '111111111';
}else{
echo '0000000';
}
}