Page 1 of 1

mcrypt_encrypt

Posted: Sun May 04, 2008 12:51 pm
by abalfazl
Hi

Description
int mcrypt_get_iv_size ( string $cipher , string $mode )

mcrypt_get_iv_size() returns the size of the Initialisation Vector (IV) in bytes. On error the function returns FALSE. If the IV is ignored in the specified cipher/mode combination zero is returned.
1-What is Initialisation Vector (IV)?


PHP Code:

Code: Select all

 
<?php
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $key = "This is a very secret key";
    $text = "Meet me at 11 o'clock behind the monument.";
    echo strlen($text) . "\n";
 
    $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
    echo strlen($crypttext) . "\n";
?>
 

Code: Select all

 
2-What does $iv_size do?why does it use mcrypt_create_iv($iv_size, MCRYPT_RAND); ???

Anyone can explain about mechanism of encryption in PHP?


Do you know good tutorial for that?