Page 1 sur 1

Fonction cryptage : problème format de sortie

Posté : 26 déc. 2011, 23:03
par zzzzzz
Bonjour j'utilise 2 fonctions, une pour crypter, une pour decrypter. Pour être franc je n'y comprend RIEN.

Aucun problème pour crypter, mais pour decrypter il n'y a RIEN qui s'affiche (en echo) a la sortie de la fonction.

function Crypter($str, $key)
{
# Add PKCS7 padding.
$block = mcrypt_get_block_size('des', 'ecb');
if (($pad = $block - (strlen($str) % $block)) < $block) {
$str .= str_repeat(chr($pad), $pad);
}

return bin2hex(mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB));
}

function Decrypt($str, $key)
{
$str = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);

# Strip padding out.
$block = mcrypt_get_block_size('des', 'ecb');
$pad = ord($str[($len = strlen($str)) - 1]);
if ($pad && $pad < $block && preg_match(
'/' . chr($pad) . '{' . $pad . '}$/', $str
)
) {
return substr($str, 0, strlen($str) - $pad);
}
return $str;
}


J'ai essayé des fonctions hex2bin qu'on trouve sur le PHP officiel (hex2bin n'existe pas dans PHP5), rien à faire ca n'affiche rien en echo. Peut être qu'il ne s'agit pas de faire de hex à bin ?

Merci d'avance pour votre aide... :D