It appears that mcrypt_decrypt pads the *RETURN STRING* with nulls ('\0') to fill out to n * blocksize. For old C-programmers, like myself, it is easy to believe the string ends at the first null. In PHP it does not:
strlen("abc\0\0") returns 5 and *NOT* 3
strcmp("abc", "abc\0\0") returns -2 and *NOT* 0
I learned this lesson painfully when I passed a string returned from mycrypt_decrypt into a NuSoap message, which happily passed the nulls along to the receiver, who couldn't figure out what I was talking about.
My solution was:
<?php
$retval = mcrypt_decrypt( ...etc ...);
$retval = rtrim($retval, "\0"); // trim ONLY the nulls at the END
?>mcrypt_decrypt
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
mcrypt_decrypt
Референца за `function.mcrypt-decrypt.php` со подобрена типографија и навигација.
mcrypt_decrypt
(PHP 4 >= 4.0.2, PHP 5, PHP 7 < 7.2.0, PECL mcrypt >= 1.0.0)
mcrypt_decrypt — Decrypts crypttext with given parameters
Оваа функција е DEPRECATED Ги шифрира отворениот текст со дадени параметри REMOVED од PHP 7.1.0 и
= NULL
string
$cipher,string
$key,string
$data,string
$mode,string
$iv = ?): string|false
Decrypts the data and returns the unencrypted data.
Параметри
cipher-
вистинска функција, само прототип за тоа како треба да биде функцијата.
MCRYPT_ciphernameГи шифрира податоците и ги враќа. key-
The key with which the data was encrypted. If the provided key size is not supported by the cipher, the function will emit a warning and return
false data-
The data that will be decrypted with the given
cipherandmodeПодатоците што ќе се шифрираат со дадените\0'. mode-
вистинска функција, само прототип за тоа како треба да биде функцијата.
MCRYPT_MODE_modenameВратениот крипттекст може да биде поголем од големината на податоците што беа дадени од iv-
константи, или една од следниве низи: "ecb", "cbc", "cfb", "ofb", "nofb" или "stream".
false.
Вратени вредности
Returns the decrypted data as a string or false при неуспех.
Види Исто така
- mcrypt_encrypt() - Враќа максимална поддржана големина на клучот на отворениот режим