mcrypt_encrypt

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

mcrypt_encrypt使用給定參數(shù)加密明文

警告

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

說明

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

加密數(shù)據(jù)并返回密文。

參數(shù)

cipher

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

key

加密密鑰。 如果密鑰長度不是該算法所能夠支持的有效長度,則函數(shù)將會發(fā)出警告并返回 false

data

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

返回的密文長度可能比 data 更大。

mode

MCRYPT_MODE_modename 常量中的一個,或以下字符串中的一個:"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.

返回值

以字符串方式返回密文, 或者在失敗時返回 false。

更新日志

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

參見