getKey(), OPENSSL_RAW_DATA, $iv); $encryptedWithIv = $iv . $encrypted; return base64_encode($encryptedWithIv); } /** * Decrypt * @param string $encryptedData * @return bool|string */ public function decrypt(string $encryptedData): bool|string { $encodedData = base64_decode($encryptedData); $ivSize = openssl_cipher_iv_length('aes-256-cbc'); $iv = mb_substr($encodedData, 0, $ivSize, '8bit'); $encryptedData = mb_substr($encodedData, $ivSize, null, '8bit'); return openssl_decrypt($encryptedData, 'aes-256-cbc', $this->getKey(), OPENSSL_RAW_DATA, $iv); } }