PHP/Utility Function/mcrypt enc get iv size

Материал из Web эксперт
Перейти к: навигация, поиск

Using Mcrypt generic

   <source lang="html4strict">

<?php

   $plaintext = "this is a test";
   $password = "enigma";
   $cipher = mcrypt_module_open("blowfish", "", "ecb", "");
   $iv_size = mcrypt_enc_get_iv_size($cipher);
   srand();
   $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
   mcrypt_generic_init($cipher, $password, $iv);
   $ciphertext = mcrypt_generic($cipher, $plaintext);
   mcrypt_generic_deinit($cipher);
   mcrypt_module_close($cipher);
   file_put_contents("secret_message.txt", $iv . $ciphertext);

?>

 </source>