In PHP, the mcrypt_decrypt() function is used to decrypt ciphertext using given parameters, the syntax is "mcrypt_decrypt($cipher,$key,$data,$mode,$iv)"; parameter "$key" is the data encryption key and "$data" is the data decrypted using the given "$cipher" and "$mode".
The operating environment of this tutorial: windows7 system, PHP8 version, DELL G3 computer
php mcrypt_decrypt() function
mcrypt_decrypt — Use the given parameters to decrypt ciphertext, syntax format:
mcrypt_decrypt( string $cipher, string $key, string $data, string $mode, string $iv = ? ): string|false
can decrypt data and return plaintext.
Parameters:
cipher
MCRYPT_ciphername One of the constants, or the name of the algorithm as a string value.
key
Data encryption key. If the key length is not a valid length supported by the encryption and decryption algorithm, a warning will be generated and false will be returned
data
To be decrypted using the given cipher and mode data. If the data size is not n * group size, it is padded by appending '\0'.
mode
MCRYPT_MODE_modename One of the constants, or one of the following strings: "ecb", "cbc", "cfb", "ofb", " nofb" and "stream".
iv
is used for initialization in CBC, CFB, OFB modes, and some algorithms in STREAM mode. If the link mode does not support the supplied IV size, or if no IV is provided but the link mode requires one, the function will issue a warning and return FALSE.
Return value:
Return the decrypted data in string format, or return false on failure.
Usage example:
The above routine will output:
Key size: 32 ENJW8mS2KaJoNB5E5CoSAAu0xARgsR1bdzFWpEn+poYw45q+73az5kYi4j+0haevext1dGrcW8Qi59txfCBV8BBj3bzRP3dFCp3CPQSJ8eU= This string was AES-256 / CBC / ZeroBytePadding encrypted.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to use php mcrypt_decrypt() function. For more information, please follow other related articles on the PHP Chinese website!