Discussion:
Problem with mbstring.internal_encoding, mcrypt and php-fpm
Condor
2013-09-23 12:23:39 UTC
Permalink
Hello,

from two days I have strange problem with this param
mbstring.internal_encoding on nginx and php-fpm.
I use php version 5.4.20 and when I setting mbstring.internal_encoding I
have a problem with mcrypt.

NOTICE: PHP message: PHP Warning: mcrypt_generic_init(): Iv size
incorrect; supplied length: 12, needed: 8 in file.php

I setup php.ini file:

zend.multibyte = On
default_mimetype = "text/html"
default_charset = "UTF-8"
mbstring.internal_encoding = UTF-8



and here is function:

85 private function decrypt($blob)
86 {
87 $deckey = $_SESSION['key'];
88 $realkey = sha1($deckey, true);
89 $rawblob = hex2bin($blob); /* binary blob */
90 $td = mcrypt_module_open($this->CIPHER, "",
MCRYPT_MODE_CFB, "");
91 $iv = mb_substr($rawblob, 0,
mcrypt_enc_get_iv_size($td)); /* IV */
92 if (mb_strlen($iv) < mcrypt_enc_get_iv_size($td))
return FALSE;
93 $ct = mb_substr($rawblob,
mcrypt_enc_get_iv_size($td)); /* CipherText */
94 ---> mcrypt_generic_init($td, $realkey, $iv);
95 $unblob = mdecrypt_generic($td, $ct);
96 mcrypt_generic_deinit($td);
97 $pt = mb_substr($unblob, 20);
98 $check = mb_substr($unblob, 0, 20);
99 if ($check != sha1($pt, true))
100 {
101 return FALSE;
102 } else {
103 return $pt;
104 }
105 }


The same code with the same config options is worked fine with apache
httpd.

Any one can give me a little help ?
Thanks

Regards,
Hristo S.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
2013-09-23 12:42:04 UTC
Permalink
Hristo,

Try changing the php.ini config:

mbstring.func_overload 0

See if that helps your issue, more on what it does:
http://php.net/manual/en/mbstring.overload.php

Aziz
Post by Condor
Hello,
from two days I have strange problem with this param
mbstring.internal_encoding on nginx and php-fpm.
I use php version 5.4.20 and when I setting mbstring.internal_encoding I
have a problem with mcrypt.
NOTICE: PHP message: PHP Warning: mcrypt_generic_init(): Iv size
incorrect; supplied length: 12, needed: 8 in file.php
zend.multibyte = On
default_mimetype = "text/html"
default_charset = "UTF-8"
mbstring.internal_encoding = UTF-8
85 private function decrypt($blob)
86 {
87 $deckey = $_SESSION['key'];
88 $realkey = sha1($deckey, true);
89 $rawblob = hex2bin($blob); /* binary blob */
90 $td = mcrypt_module_open($this->**CIPHER, "",
MCRYPT_MODE_CFB, "");
91 $iv = mb_substr($rawblob, 0,
mcrypt_enc_get_iv_size($td)); /* IV */
92 if (mb_strlen($iv) < mcrypt_enc_get_iv_size($td))
return FALSE;
93 $ct = mb_substr($rawblob,
mcrypt_enc_get_iv_size($td)); /* CipherText */
94 ---> mcrypt_generic_init($td, $realkey, $iv);
95 $unblob = mdecrypt_generic($td, $ct);
96 mcrypt_generic_deinit($td);
97 $pt = mb_substr($unblob, 20);
98 $check = mb_substr($unblob, 0, 20);
99 if ($check != sha1($pt, true))
100 {
101 return FALSE;
102 } else {
103 return $pt;
104 }
105 }
The same code with the same config options is worked fine with apache
httpd.
Any one can give me a little help ?
Thanks
Regards,
Hristo S.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Condor
2013-09-23 12:54:04 UTC
Permalink
Post by Aziz Saleh
Hristo,
mbstring.func_overload 0
http://php.net/manual/en/mbstring.overload.php [3]
Aziz
Post by Condor
Hello,
from two days I have strange problem with this param
mbstring.internal_encoding on nginx and php-fpm.
I use php version 5.4.20 and when I setting
mbstring.internal_encoding I have a problem with mcrypt.
NOTICE: PHP message: PHP Warning:  mcrypt_generic_init(): Iv size
incorrect; supplied length: 12, needed: 8 in file.php
zend.multibyte = On
default_mimetype = "text/html"
default_charset = "UTF-8"
mbstring.internal_encoding = UTF-8
 85         private function decrypt($blob)
 86         {
 87                 $deckey = $_SESSION['key'];
 88                 $realkey = sha1($deckey, true);
 89                 $rawblob = hex2bin($blob); /* binary
blob */
 90                 $td =
mcrypt_module_open($this->CIPHER, "", MCRYPT_MODE_CFB, "");
 91                 $iv = mb_substr($rawblob, 0,
mcrypt_enc_get_iv_size($td)); /* IV */
 92                 if (mb_strlen($iv) <
mcrypt_enc_get_iv_size($td)) return FALSE;
 93                 $ct = mb_substr($rawblob,
mcrypt_enc_get_iv_size($td)); /* CipherText */
 94    --->         mcrypt_generic_init($td, $realkey, $iv);
 95                 $unblob = mdecrypt_generic($td, $ct);
 96                 mcrypt_generic_deinit($td);
 97                 $pt = mb_substr($unblob, 20);
 98                 $check = mb_substr($unblob, 0, 20);
 99                 if ($check != sha1($pt, true))
100                 {
101                         return FALSE;
102                 } else {
103                         return $pt;
104                 }
105         }
The same code with the same config options is worked fine with
apache httpd.
Any one can give me a little help ?
Thanks
Regards,
Hristo S.
Hello,

I just try and no effect after reload the php-fpm.

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