暗号化のアップグレード
ドキュメント
変更点
PHP 7.2以降非推奨となった
MCrypt
のサポートは削除されました。
アップグレードガイド
設定ファイル内の
$config['encryption_key'] = 'abc123';
は、**application/config/config.php**から**app/Config/Encryption.php**内のpublic $key = 'abc123';
に移動しました。CI3の暗号化で暗号化されたデータを復号化する必要がある場合は、互換性を維持するための設定を構成します。 CI3との互換性を維持するための設定を参照してください。
暗号化ライブラリを使用している箇所ではすべて、
$this->load->library('encryption');
を$encrypter = service('encrypter');
に置き換え、次のコード例のように暗号化と復号化のメソッドを変更する必要があります。
コード例
CodeIgniterバージョン3.x
<?php
$this->load->library('encryption');
$plain_text = 'This is a plain-text message!';
$ciphertext = $this->encryption->encrypt($plain_text);
// Outputs: This is a plain-text message!
echo $this->encryption->decrypt($ciphertext);
CodeIgniterバージョン4.x
<?php
$encrypter = service('encrypter');
$plainText = 'This is a plain-text message!';
$ciphertext = $encrypter->encrypt($plainText);
// Outputs: This is a plain-text message!
echo $encrypter->decrypt($ciphertext);