CI_Encrypt::encode_from_legacy PHP Method

encode_from_legacy() public method

Takes an encoded string from the original Encryption class algorithms and returns a newly encoded string using the improved method added in 2.0.0 This allows for backwards compatibility and a method to transition to the new encryption algorithms. For more details, see https://codeigniter.com/user_guide/installation/upgrade_200.html#encryption
public encode_from_legacy ( $string, $legacy_mode = MCRYPT_MODE_ECB, $key = '' ) : string
return string
    public function encode_from_legacy($string, $legacy_mode = MCRYPT_MODE_ECB, $key = '')
    {
        if (preg_match('/[^a-zA-Z0-9\\/\\+=]/', $string)) {
            return FALSE;
        }
        // decode it first
        // set mode temporarily to what it was when string was encoded with the legacy
        // algorithm - typically MCRYPT_MODE_ECB
        $current_mode = $this->_get_mode();
        $this->set_mode($legacy_mode);
        $key = $this->get_key($key);
        $dec = base64_decode($string);
        if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE) {
            $this->set_mode($current_mode);
            return FALSE;
        }
        $dec = $this->_xor_decode($dec, $key);
        // set the mcrypt mode back to what it should be, typically MCRYPT_MODE_CBC
        $this->set_mode($current_mode);
        // and re-encode
        return base64_encode($this->mcrypt_encode($dec, $key));
    }