使用給定參數解密密文

mcrypt_decrypt

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

mcrypt_decrypt使用給定參數解密密文

警告

本函式已自 PHP 7.1.0 起廢棄並將自 PHP 7.2.0 起移除。強烈建議不要使用本函式。

說明

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

解密 data 並返回明文。

參數

cipher

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

key

數據加密金鑰。 如果金鑰長度不是加解密演算法能夠支援的有效長度, 那麼會產生警告並且返回 false

data

要使用給定的 ciphermode 解密的數據。 如果數據大小不是 n * 分組大小,則在其後追加 '\0' 來補齊。

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 參數。 如果參數長度無效,則 mcrypt_decrypt() 函式會產生警告並且返回 false。 之前版本中,對於長度不足的金鑰和初始向量會在其後補齊 '\0' 使其達到有效長度。

參見

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *