,.?/\'') ) ); $random = ''; for ($i = 0; $i < static::IV_LENGTH; $i++) { $random .= $permitted_chars[mt_rand(0, (static::IV_LENGTH) - 1)]; } } else { throw new RuntimeException('Unable to generate initialization vector (IV)'); } } } } return $random; } protected static function getPaddedText(string $plainText): string { $stringLength = strlen($plainText); if ($stringLength % static::BLOCK_SIZE) { $plainText = str_pad($plainText, $stringLength + static::BLOCK_SIZE - $stringLength % static::BLOCK_SIZE, "\0"); } return $plainText; } public static function encrypt(string $plainText, string $key, string $iv): string { $plainText = static::getPaddedText($plainText); return base64_encode(openssl_encrypt($plainText, static::CIPHER, $key, OPENSSL_RAW_DATA, $iv)); } public static function decrypt(string $encryptedText, string $key, string $iv): string { return openssl_decrypt(base64_decode($encryptedText), static::CIPHER, $key, OPENSSL_RAW_DATA, $iv); } } ?>