private static function _aesEncrypt($data, $secret)
{
if (!is_string($data)) {
throw new \InvalidArgumentException('Input parameter "$data" must be a string.');
}
if (!function_exists("openssl_encrypt")) {
throw new \SimpleSAML_Error_Exception('The openssl PHP module is not loaded.');
}
$raw = defined('OPENSSL_RAW_DATA') ? OPENSSL_RAW_DATA : true;
$key = openssl_digest($secret, 'sha256');
$method = 'AES-256-CBC';
$ivSize = 16;
$iv = substr($key, 0, $ivSize);
return $iv . openssl_encrypt($data, $method, $key, $raw, $iv);
}