2014-04-17 1 views
2

Je suis essayer de crypter les données suivantes en utilisant le 3des (CBC) en utilisant une clé secrète et IV spec en php mais je ne reçois pas la même sortie que je reçois sur cet outil en ligne (http://symmetric-ciphers.online-domain-tools.com/)Code PHP à crypter en utilisant l'algorithme 3DES en utilisant le mode CBC et une clé secrète et IV clé

//input 
$data = "Id=120278;timestamp=2009-02-05 08:28:39.195"; 
$key = "80127ECD5E40BB25DB14354A3795880DF2B459BB08E1EE6D"; 
$iv = "331BA9C5A7446C98"; 

//output from online tool. I should get the same result in my php code 
$result = "1C80CBCE1713128176499C7A3DFB8779156B31B8DEF2F667A7100F1C3AEFABACB24283CFDF 5D312D A0074897138684BC"; 

suivant le code PHP i essayé

$string = "Id=120278;timestamp=2009-02-05 08:28:39.195"; 
$iv = "331BA9C5A7446C98"; 
$passphrase = "80127ECD5E40BB25DB14354A3795880DF2B459BB08E1EE6D"; 
$encryptedString = encryptString($string, $passphrase, $iv); 

function encryptString($unencryptedText, $passphrase, $iv) { 
    $enc = mcrypt_encrypt(MCRYPT_3DES, $passphrase, $unencryptedText, MCRYPT_MODE_CBC, $iv); 
    return base64_encode($enc); 
} 

Répondre

0

Essayez ceci:

function encrypt3DES($key,$iv,$text_enc){ 
     $block = mcrypt_get_block_size('tripledes', 'cbc'); 
     $pad = $block - (strlen($text_enc) % $block); 
     $text_enc .= str_repeat(chr($pad), $pad); 
     $text_enc = mcrypt_encrypt(MCRYPT_3DES, $key, $text_enc, MCRYPT_MODE_CBC, $iv); 
     $text_enc = base64_encode ($text_enc); 
     return $text_enc; 
    } 
Questions connexes