mcrypt_decrypt

(PHP 4 >= 4.0.2, PHP 5, PHP 7 < 7.2.0, PECL mcrypt >= 1.0.0)

mcrypt_decrypt使用給定參數(shù)解密密文

警告

本函數(shù)已自 PHP 7.1.0 起廢棄并將自 PHP 7.2.0 起移除。強(qiáng)烈建議不要使用本函數(shù)。

說(shuō)明

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

解密 data 并返回明文。

參數(shù)

cipher

MCRYPT_ciphername 常量中的一個(gè),或者是字符串值的算法名稱。

key

數(shù)據(jù)加密密鑰。 如果密鑰長(zhǎng)度不是加解密算法能夠支持的有效長(zhǎng)度, 那么會(huì)產(chǎn)生警告并且返回 false

data

要使用給定的 ciphermode 解密的數(shù)據(jù)。 如果數(shù)據(jù)大小不是 n * 分組大小,則在其后追加 '\0' 來(lái)補(bǔ)齊。

mode

MCRYPT_MODE_modename 常量中的一個(gè),或以下字符串中的一個(gè):"ecb","cbc","cfb","ofb","nofb" 和 "stream"。

iv

Used for the initialization in CBC, CFB, OFB modes, and in some algorithms in STREAM mode. If the provided IV size is not supported by the chaining mode or no IV was provided, but the chaining mode requires one, the function will emit a warning and return false.

返回值

以字符串格式返回解密后的數(shù)據(jù), 或者在失敗時(shí)返回 false。

更新日志

版本 說(shuō)明
5.6.0 不再接受無(wú)效長(zhǎng)度的 key and iv 參數(shù)。 如果參數(shù)長(zhǎng)度無(wú)效,則 mcrypt_decrypt() 函數(shù)會(huì)產(chǎn)生警告并且返回 false。 之前版本中,對(duì)于長(zhǎng)度不足的密鑰和初始向量會(huì)在其后補(bǔ)齊 '\0' 使其達(dá)到有效長(zhǎng)度。

參見(jiàn)