16) { $iv = str_pad($iv, 16, '0'); } $encrypted = openssl_encrypt($code, 'aes-256-cbc', $encryption_key, OPENSSL_RAW_DATA, $iv); // Append the $iv variable to use for decrypting later. return base64_encode($encrypted . '::' . $iv); } /** * Decrypt code using OpenSSL * * @param string $code The code to decrypt. */ public static function decrypt($code) { $encryption_key = base64_decode(SECURE_AUTH_KEY); // Grab the $iv from earlier, to decrypt. list($encrypted_data, $iv) = explode('::', base64_decode($code), 2); if (strlen($iv) < 16 || strlen($iv) > 16) { $iv = str_pad($iv, 16, '0'); } return openssl_decrypt($encrypted_data, 'aes-256-cbc', $encryption_key, OPENSSL_RAW_DATA, $iv); } }