[EMAIL PROTECTED] wrote:
Hi all,
i'm trying to crypt and decrypt password with the code below but i get many warnings

Warning: mcrypt_get_iv_size(): Module initialization failed in /web/htdocs/www.automationsoft.biz/home/invio_mail.php on line 36

Warning: mcrypt_create_iv(): Can not create an IV with size 0 or smaller in /web/htdocs/www.automationsoft.biz/home/invio_mail.php on line 37

Warning: mcrypt_decrypt(): Module initialization failed in /web/htdocs/www.automationsoft.biz/home/invio_mail.php on line 38
and i don't understand why, any help is appreciated.
Code is below.


This code is in a script //Start crypt
$iv_size=mcrypt_get_iv_size(MCRYPT_BLOWFISH,MYCRYPT_MODE_CBC);
should be...
$iv_size=mcrypt_get_iv_size(MCRYPT_BLOWFISH,MYCRYPT_MODE_ECB);
  $iv=mcrypt_create_iv($iv_size,MCRYPT_RAND);
  $key=genera();// genera() function for rand number
  $emailcifrata=mcrypt_encrypt(MCRYPT_BLOWFISH,$key,$email,MYCRYPT_MODE_CBC,$iv);
should be...
$emailcifrata=mcrypt_encrypt(MCRYPT_BLOWFISH,$key,$email,MYCRYPT_MODE_ECB,$iv);
$emailcifrata=$key.$emailcifrata;
// End crypt
This code is in another script that isn't the same script of previous //Start decrypt
$emailcifrata=fgets($fp);
$lunghezza_str=strlen($emailcifrata);
$emailcifrata=substr($emailcifrata,10);
$key=substr($emailcifrata,0,($lunghezza_str-10));
$iv_size=mcrypt_get_iv_size(MCRYPT_BLOWFISH,MYCRYPT_MODE_CBC);
should be...
$iv_size=mcrypt_get_iv_size(MCRYPT_BLOWFISH,MYCRYPT_MODE_ECB);
  $iv=mcrypt_create_iv($iv_size,MCRYPT_RAND);
  $email=mcrypt_decrypt(MCRYPT_BLOWFISH,$key,$email,MYCRYPT_MODE_CBC,$iv);
should be...
$email=mcrypt_decrypt(MCRYPT_BLOWFISH,$key,$email,MYCRYPT_MODE_ECB,$iv);
// End decrypt

Thanks in advance.

And the reason why is the streaming mode CBC doesn't work with every cipher mcrypt provides, for a list of modes each cipher is compatible with from a shell issue this command...
%>/path/to/mcrypt --list


Or if you don't have access to a shell on the webserver try these...
http://us3.php.net/manual/en/function.mcrypt-list-algorithms.php
http://us3.php.net/manual/en/function.mcrypt-list-modes.php

From the help file on php.net for mcrypt
http://us3.php.net/manual/en/ref.mcrypt.php


Predefined Constants


The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

Mcrypt can operate in four block cipher modes (CBC, OFB, CFB, and ECB). If linked against libmcrypt-2.4.x or higher the functions can also operate in the block cipher mode nOFB and in STREAM mode. Below you find a list with all supported encryption modes together with the constants that are defines for the encryption mode. For a more complete reference and discussion see Applied Cryptography by Schneier (ISBN 0-471-11709-9).

*

MCRYPT_MODE_ECB (electronic codebook) is suitable for random data, such as encrypting other keys. Since data there is short and random, the disadvantages of ECB have a favorable negative effect.
*


MCRYPT_MODE_CBC (cipher block chaining) is especially suitable for encrypting files where the security is increased over ECB significantly.
*


MCRYPT_MODE_CFB (cipher feedback) is the best mode for encrypting byte streams where single bytes must be encrypted.
*


MCRYPT_MODE_OFB (output feedback, in 8bit) is comparable to CFB, but can be used in applications where error propagation cannot be tolerated. It's insecure (because it operates in 8bit mode) so it is not recommended to use it.
*


MCRYPT_MODE_NOFB (output feedback, in nbit) is comparable to OFB, but more secure because it operates on the block size of the algorithm.
*


MCRYPT_MODE_STREAM is an extra mode to include some stream algorithms like WAKE or RC4.

HTH
Jas

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to