public function encrypt(string $string, string $key): string
{
$ivLength = openssl_cipher_iv_length($this->encryptMethod);
$iv = openssl_random_pseudo_bytes($ivLength);
$salt = openssl_random_pseudo_bytes(256);
$iterations = 999;
$hashKey = hash_pbkdf2('sha512', $key, $salt, $iterations, ($this->encryptMethodLength() / 4));
$encryptedString = openssl_encrypt($string, $this->encryptMethod, hex2bin($hashKey), OPENSSL_RAW_DATA, $iv);
$encryptedString = base64_encode($encryptedString);
unset($hashKey);
$output = ['ciphertext' => $encryptedString, 'iv' => bin2hex($iv), 'salt' => bin2hex($salt), 'iterations' => $iterations];
unset($encryptedString, $iterations, $iv, $ivLength, $salt);
return base64_encode(json_encode($output));
}// encrypt