phpday 2027 - Call for Papers

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

Avviso

Questa funzione è stata DEPRECATA a partire da PHP 7.1.0 e RIMOSSA a partire da PHP 7.2.0. Fare affidamento su questa funzione è altamente sconsigliato.

Descrizione

function mcrypt_decrypt(
    string $cipher,
    string $key,
    string $data,
    string $mode,
    string $iv = ?
): string|false

Decrypts the data and returns the unencrypted data.

Elenco dei parametri

cipher

Una tra le costanti MCRYPT_ciphername, oppure il nome dell'algoritmo sotto forma di stringa.

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 cipher and mode. If the size of the data is not n * blocksize, the data will be padded with '\0'.

mode

Una tra le costanti MCRYPT_MODE_modename, oppure una tra le seguenti stringhe: "ecb", "cbc", "cfb", "ofb", "nofb" o "stream".

iv

Utilizzato per l'inizializzazione nelle modalità CBC, CFB, OFB e in alcuni algoritmi in modalità STREAM. Se la dimensione dell'IV fornito non è supportata dalla modalità di concatenamento, oppure se non è stato fornito alcun IV ma la modalità di concatenamento lo richiede, la funzione emetterà un warning e restituirà false.

Valori restituiti

Returns the decrypted data as a string o false in caso di fallimento.

Vedere anche:

+add a note

User Contributed Notes 1 note

up
31
eddiec at stararcher dot com
21 years ago
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
?>
To Top