Bonjour, j'ai un probleme avec la fonction mcrypt, ou devrais-je dire avec la fonction decrypt...
j'ai creer une classe permettant d'encrypter et de decrypter une phrase :
--------------------------------------------------------------------------------
class Crypt
{
var $td, $iv, $ks, $key, $chaine;
var $encrypted, $decrypted;
function Get_all()
{
$this->td = mcrypt_module_open(MCRYPT_TripleDES, '', MCRYPT_MODE_CBC, '');
$this->iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), MCRYPT_RAND);
$this->ks = mcrypt_enc_get_key_size($this->td);
$this->key = substr(md5("ma clef très secrète"), 0, $this->ks);
$this->chaine = "Nique les poules";
}
function Encrypt()
{
$this->Get_all();
mcrypt_generic_init($this->td, $this->key, $this->iv);
$this->encrypted = mcrypt_generic($this->td, $this->chaine);
mcrypt_generic_deinit($this->td);
mcrypt_module_close($this->td);
echo "Encrypt : ".trim($this->encrypted)."<br />\n";
}
function Decrypt()
{
$this->Get_all();
mcrypt_generic_init($this->td, $this->key, $this->iv);
$this->decrypted = mdecrypt_generic($this->td, $this->encrypted);
mcrypt_generic_deinit($this->td);
mcrypt_module_close($this->td);
echo "Decrypt : ".trim($this->decrypted)."<br />\n";
}
}
$crypt = new Crypt();
$crypt->Encrypt();
$crypt->Decrypt();
--------------------------------------------------------------------------------
et cela affiche :
---------------
Encrypt : nè>©ÏSG|é«YžQv©
Decrypt : ê¹¢Gg ™s poules
---------------
Le problème que je ne comprends pas est qu'il n'affiche pas "Nique les poules" et qu'il ne me met seulement "s poules" de bon.
Quelqu'un saurait-il d'ou ca vient ?
Merci d'avance.
Si la connaissance peut creer des problemes, ce n'est pas par l'ignorance que l'on peut les resoudre. -- Isaac Asimov