Salve... non so perchè ma non riesco più a criptare le stringhe e decriptarle in modo corretto.
Per non postare tutto il codice che ho fatto ho provato il codice di php.net notando lo stesso problema:
Codice PHP:
<?PHP
$stuff="String to enc/enc/dec/dec =,=,";
$key="XiTo74dOO09N48YeUmuvbL0E";
function nl() {
echo "
\n";
}
$iv = mcrypt_create_iv (mcrypt_get_block_size (MCRYPT_TripleDES, MCRYPT_MODE_CBC), MCRYPT_DEV_RANDOM);
// Encrypting
function encrypt($string, $key) {
$enc = "";
global $iv;
$enc=mcrypt_cbc (MCRYPT_TripleDES, $key, $string, MCRYPT_ENCRYPT, $iv);
return base64_encode($enc);
}
// Decrypting
function decrypt($string, $key) {
$dec = "";
$string = trim(base64_decode($string));
global $iv;
$dec = mcrypt_cbc (MCRYPT_TripleDES, $key, $string, MCRYPT_DECRYPT, $iv);
return $dec;
}
$encrypted = encrypt($stuff, $key);
$decrypted = decrypt($encrypted, $key);
echo "Encrypted is ".$encrypted . nl();
echo "Decrypted is ".$decrypted . nl();
?>
il risultato:
codice:
Encrypted is bMJPZOM6bdPhRYQNdHj0Cxow0btrzqTTuYePfs/65qg=
Decrypted is String to enc/enc/dec/dec =,=,��
Ci sono quei ?? al fondo... che sono di numero variabile, quindi non posso neanche eliminare manualmente
Qualcuno sa il perchè?