Sunday 30 September 2012

mcrypt_decrypt - Decrypts crypttext with given parameters

string mcrypt_decrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] )
Decrypts crypttext with given parameters
Decrypts the data and returns the unencrypted data.

Caution, MCRYPT_RIJNDAEL_256 is not equivalent to AES_256.





The way to make RIJNDAEL be decrypted from AES with openssl is to use MCRYPT_RIJNDAEL_128 and padd the string to encrypt before encrypting with the follwing function:





<?php
function pkcs5_pad ($text, $blocksize) {
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
?>




On the decryption, the choosing of AES_256 or AES_128, etc. is based on the keysize used in the crypting. In my case it was a 128bit key so I used AES_128.


073 PHP من الألف إلى الياء Arabic التعامل مع النصوص Strings pt9