How to use php mcrypt_decrypt() function

青灯夜游
Release: 2023-03-17 18:24:02
Original
2356 people have browsed it

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".

How to use php mcrypt_decrypt() function

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
Copy after login

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:

Copy after login

The above routine will output:

Key size: 32 ENJW8mS2KaJoNB5E5CoSAAu0xARgsR1bdzFWpEn+poYw45q+73az5kYi4j+0haevext1dGrcW8Qi59txfCBV8BBj3bzRP3dFCp3CPQSJ8eU= This string was AES-256 / CBC / ZeroBytePadding encrypted.
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!