Sunday, 30 September 2012

json_encode - Returns the JSON representation of a value

string json_encode ( mixed $value [, int $options = 0 ] )
Returns the JSON representation of a value
Returns a string containing the JSON representation of value.

<?php
$arr 
= array('a' => 1'b' => 2'c' => 3'd' => 4'e' => 5);

echo 
json_encode($arr);?>

5.4.0 JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, and JSON_UNESCAPED_UNICODE options were added. 5.3.3 JSON_NUMERIC_CHECK option was added. 5.3.0 The options parameter was added.

JSON - PHP y Javascript

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